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? Choose 2 answers
To fire an exception in Apex, the developer must use the throw statement along with an instance of the exception.
Option A: throw new ParityException();
Correct Way.
Creates a new instance of ParityException with no message and throws it.
Syntax is correct for throwing an exception.
Option C: throw new ParityException('parity does not match');
Correct Way.
Creates a new instance of ParityException with a custom message and throws it.
The exception class inherits from Exception, which allows passing a message to the constructor.
Options Not Correct:
Option B: new ParityException('parity does not match');
Incorrect.
This statement creates a new instance of ParityException but does not throw it.
Without the throw keyword, the exception is not fired.
Option D: new ParityException();
Incorrect.
Similar to Option B, this creates a new instance but does not throw it.
The exception will not affect the flow unless it is thrown.
Conclusion:
The two ways the developer can fire the exception are:
Option A: throw new ParityException();
Option C: throw new ParityException('parity does not match');
Both use the throw statement to fire the exception.
Melissa
1 months agoFausto
1 months agoPamella
2 months agoGalen
2 months agoNovella
7 days agoAlmeta
8 days agoTwana
13 days agoElina
17 days agoFelton
18 days agoEdwin
1 months agoCoral
1 months agoAmalia
2 months ago