https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_custom.htm
"To create your custom exception class, extend the built-in Exception class and make sure your class name ends with the word Exception, such as “MyException” or “PurchaseException”."
Technically a custom exception class can extend another class that itself extends the System extension class, so you could argue that E could also be correct, but if its a toss up between D and E, I'd say D is "more" correct
A, B, D - easy to get by elimination even if you're not certain about D (C contradicts B and E, E is false due to lack of multiple inheritance in Apex)
While options A and B are agreed upon as the correct answers, there seems to be confusion among people on whether to choose option D or E as the third correct answer.
Here's my take.
Both options D and E are partially correct, but option E is the more accurate choice as a third correct answer.
Here's why,
Option D states that a custom exception class name must end with "Exception", which is not entirely true. While it is common to name custom exceptions with the "Exception" suffix, it is not a strict requirement.
Option E, on the other hand, states that a custom exception class can extend other classes besides the Exception class, which is true. Custom exception classes can indeed extend other classes or implement interfaces, allowing for greater flexibility in handling exceptions.
Multiple inheritance is not allowed in Apex - you can implement many interfaces but not extend many classes (well, unless you want to argue that Exception extends Object so it's two classes extended...)
I also thought that D was a best practice and not a requirement but instead it is!
If you try to create a custom exception class whose name does not terminate with "Exception" you will get compile error: "Classes extending Exception must have a name ending in Exception: <class_name>"
Seems ABE options are correct. D is not correct, since you can name the class anything and without 'exception' in it. Only thing is that it should extend from exception class.
Nope. exception classes has to end with the word Exception. It won't compile otherwise. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_custom.htm
I agree: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_custom.htm
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Pally88
Highly Voted 3 years, 4 months agonoox
Highly Voted 2 years, 10 months agoNand072
Most Recent 1 year, 2 months ago1vanTT
1 year, 5 months agogovosen887
1 year, 7 months agoSasi7
1 year, 8 months agogovosen887
1 year, 7 months agoedogaldo
1 year, 2 months agoApexMike
2 years, 1 month agotapasroy
2 years, 7 months agoApexMike
2 years, 1 month agoJCTheGenius
3 years, 2 months ago