Cyber Monday 2024! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Exam CRT-450 Topic 2 Question 67 Discussion

Actual exam question for Salesforce's CRT-450 exam
Question #: 67
Topic #: 2
[All CRT-450 Questions]

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

Show Suggested Answer Hide Answer
Suggested Answer: A, C

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.


Contribute your Thoughts:

Melissa
2 days ago
I'm not sure, but I think option B is also a valid way to fire the exception by creating a new instance with a message.
upvoted 0 times
...
Fausto
3 days ago
I agree with Amalia, options A and C make sense because they involve throwing the custom exception.
upvoted 0 times
...
Pamella
6 days ago
Hmm, I was thinking B and D were the right choices, but now I'm not so sure. Looks like I need to review my exception handling knowledge.
upvoted 0 times
...
Galen
9 days ago
I'm pretty sure the correct answers are A and C. Throwing the exception is the way to go, and you can include a message with it.
upvoted 0 times
Coral
4 days ago
User 1: I think the correct answers are A and C.
upvoted 0 times
...
...
Amalia
23 days ago
I think the correct ways to fire the exception are A and C.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77