CRT-450 practice question 15 of 30
A developer creates a custom exception as shown below: public class ParityException extends Exception { } What are two ways the developer can fire the exception in Apex?
Full set: 201 questionsIn Apex, "firing" or "raising" an exception is accomplished using the throw statement. This statement interrupts the normal execution flow and passes an instantiated exception object to the runtime. Options A and B both correctly use the throw keyword followed by the instantiation of the ParityException object using the new keyword. Although the custom ParityException class does not explicitly define constructors, it inherits them from the base Exception class. This includes a no-argument constructor (used in A) and a constructor that accepts a String message (used in B). Apex is case-insensitive for class and variable names, so parityException resolves to ParityException.
1. Salesforce Apex Developer Guide
"Exception Handling": The guide explicitly states
"To fire an exception
use the throw statement." This confirms that the throw keyword is mandatory for the action described in the question.
2. Salesforce Apex Developer Guide
"Using Custom Exceptions": This section provides examples that demonstrate the correct syntax for firing a custom exception
which is throw new MyException('Error message');. This directly supports the patterns in options A and B.
3. Salesforce Apex Developer Guide
"Exception Class and Built-In Exceptions": This documentation details the base Exception class
from which all other exceptions inherit. It documents the available constructors
including Exception() and Exception(message)
which are inherited by the custom ParityException class
validating the instantiation methods in both A and B.
4. Salesforce Apex Developer Guide
"Apex Language Constructs"
"Case Sensitivity": This section clarifies that "Apex is case-insensitive
" which validates that parityException in option B is syntactically correct and will be treated the same as ParityException.
Keep practicing
Take the free CRT-450 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CRT-450 practice questions
- Question 2A developer created a child Lightning web component nested inside a parent Lightning web …
- Question 4A developer needs to make a custom Lightning Web Component available in the Salesforce Cl…
- Question 6Given the following Apex statement: Account myAccount = [SELECT Id, Name FROM Account); W…
- Question 8Which action causes a before trigger to fire by default for Accounts?
- Question 9Universal Containers (UC) wants to lower its shipping cost while making the shipping proc…
- Question 10A custom picklist field, Pool Preference ¢, exists on a custom object. The picklist conta…
