PDI · Question #42
Which three statements are true regarding custom exceptions in Apex? (Choose three.)
The correct answer is B. A custom exception class can implement one or many interfaces. D. A custom exception class name must end with "Exception". E. A custom exception class can extend other classes besides the Exception class.. Custom Apex exception classes can implement interfaces and other classes, and their names must adhere to the 'Exception' suffix convention.
Question
Which three statements are true regarding custom exceptions in Apex? (Choose three.)
Options
- AA custom exception class must extend the system Exception class.
- BA custom exception class can implement one or many interfaces.
- CA custom exception class cannot contain member variables or methods.
- DA custom exception class name must end with "Exception".
- EA custom exception class can extend other classes besides the Exception class.
How the community answered
(61 responses)- A8% (5)
- B74% (45)
- C18% (11)
Why each option
Custom Apex exception classes can implement interfaces and other classes, and their names must adhere to the 'Exception' suffix convention.
A custom exception class is not strictly required to directly extend `System.Exception`; it must extend a class that ultimately inherits from `System.Exception`, allowing for intermediate custom exception classes.
Custom exception classes in Apex are flexible and can implement one or many interfaces, allowing them to conform to specific contracts or extend their functionality beyond simple error handling.
Custom exception classes can and often should contain member variables and methods to provide additional context, specific error codes, or helpful utility functions related to the error, enhancing the informativeness of the exception.
Salesforce development best practices and conventions dictate that custom exception class names should end with 'Exception' to clearly identify their purpose and maintain consistency with the `System.Exception` class.
A custom exception class can extend another custom exception class, which in turn extends `System.Exception`, thereby forming a hierarchy of exception types and allowing for more structured error management.
Concept tested: Custom Apex Exceptions
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_exceptions.htm
Topics
Community Discussion
No community discussion yet for this question.