I would like to know what are the constructors of Exception class in Salesforce.

I am aware of these two constructors, is there any other?

Exception(String message)

We know that Salesforce is made over Java, so can we expect Salesforce to have the same set of "Constructors" as of java

Link here

Also, I would like to know if there is a way to know how the Exception class is written in Salesforce.

  • That last question is probably not on topic here. Even if it is on topic, try to stick to one question per question.
    – Adrian Larson
    Nov 7, 2016 at 13:48
  • Hi @AdrianLarson, Thanks for your response. Kindly let me know whether I should raise a new question for the last topic.. Otherwise, if you know the answer, please let me know. Nov 8, 2016 at 7:13
  • As I said, the last question is almost certainly off topic on this forum, even if you create a separate question for it.
    – Adrian Larson
    Nov 8, 2016 at 16:35

1 Answer 1


There are also Exception constructors that accept another Exception. Take a look at Creating Custom Exceptions, which shows constructors you can define on a class that simply extends Exception without any custom body.

To create your custom exception class, extend the built-in Exception class and make sure your class name ends with the word Exception. Append extends Exception after your class declaration as follows.

public class MyException extends Exception {}

Here are some ways you can create your exceptions objects, which you can then throw.

You can construct exceptions:

  • With no arguments:

      new MyException();
  • With a single String argument that specifies the error message:

      new MyException('This is bad');
  • With a single Exception argument that specifies the cause and that displays in any stack trace:

      new MyException(e);
  • With both a String error message and a chained exception cause that displays in any stack trace:

      new MyException('This is bad', e);

So there are at least two that you did not list (the last two). The document I linked does not claim to be comprehensive, but I believe these are indeed all of the public constructors.

  • Yeah, I checked the link. Everything is described here as per MyException class. But I'm more interested on Exception class. public class MyException extends Exception {} Nov 8, 2016 at 7:17
  • 1
    @Robi That's where the constructors come from...
    – Adrian Larson
    Nov 8, 2016 at 16:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .