In many instances, if you fail the exam you are booted from the Ph.D. program and given a "terminal" master's degree.
In many others, if you fail the exam (or exams - in my case they just rolled this into the quals) you are booted from the program _without_ a masters degree.
I once spent a month teaching someone topology from scratch so that he could pass a qual he needed to get a PhD in combinatorics.
Different schools have different names for the exam. Sometimes it's written, sometimes it's oral...sometimes it's both. Depends on the school and the department.
In many instances, if you fail the exam you are booted from the Ph.D. program and given a "terminal" master's degree.