Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Plat-Dev-201 Exam - Topic 2 Question 14 Discussion

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?
A) throw new ParityException (); and B) throw new parityException ('parity does not match');
C) new ParityException ();
D) new ParityException('parity does not match');

Salesforce Plat-Dev-201 Exam - Topic 2 Question 14 Discussion

Actual exam question for Salesforce's Plat-Dev-201 exam
Question #: 14
Topic #: 2
[All Plat-Dev-201 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?

Show Suggested Answer Hide Answer
Suggested Answer: A, B

Throwing Exceptions in Apex:

throw new ExceptionType();creates a new instance and throws it.

A: No argument constructor.

B: Constructor with a custom error message.

Why Not Other Options?

C and D: These create exception instances but do not throw them, which is not valid syntax for firing an exception.


Contribute your Thoughts:

0/2000 characters
Eliseo
21 hours ago
I'm not entirely sure, but I think C and D are just creating an instance without throwing it, right?
upvoted 0 times
...
Rose
6 days ago
I remember that to throw an exception, we need to use the `throw` keyword, so A looks correct.
upvoted 0 times
...

Save Cancel