nerdexam
Salesforce

PDI · Question #228

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

The correct answer is B. throw new ParityException("parity does not match"); D. throw new ParityException(). The question asks for the correct Apex syntax to instantiate and explicitly throw a custom exception.

Submitted by haruto_sh· Apr 18, 2026Logic and Process Automation

Question

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

Options

  • Anew ParityException();:
  • Bthrow new ParityException("parity does not match");
  • Cnew ParityException('parity does not match');
  • Dthrow new ParityException();

How the community answered

(51 responses)
  • A
    4% (2)
  • B
    94% (48)
  • C
    2% (1)

Why each option

The question asks for the correct Apex syntax to instantiate and explicitly throw a custom exception.

Anew ParityException();:

Instantiating an exception with `new ParityException();` only creates an object but does not fire or propagate the exception without the `throw` keyword.

Bthrow new ParityException("parity does not match");Correct

The `throw` keyword is essential to fire an exception, and `new ParityException("parity does not match")` correctly instantiates the custom exception with a message parameter.

Cnew ParityException('parity does not match');

Instantiating an exception with `new ParityException('parity does not match');` only creates an object with a message but does not fire or propagate the exception without the `throw` keyword.

Dthrow new ParityException();Correct

The `throw` keyword is essential to fire an exception, and `new ParityException()` correctly instantiates the custom exception without a specific message, using its default constructor.

Concept tested: Throwing custom Apex exceptions

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_creating_exceptions.htm

Topics

#Apex Exceptions#Custom Exceptions#Throw Keyword#Error Handling

Community Discussion

No community discussion yet for this question.

Full PDI Practice