I'd like to extend Exception to create a custom exception class that takes several arguments in addition to the standard string message.
I've found examples showing basic inheritance (An Introduction to Exception Handling) and adding custom constructors (Extended Class Example).
public virtual class MyException extends Exception {
public Double d;
// Exception class constructor
MyException(string message, Double d) {
// How can I pass 'message' to the base constructor?
this.d = d;
}
}
When using a custom exception similar to the example above calls to getMessage() return 'Script-thrown exception', which makes sense as message hasn't been utilized yet.
How can I extend Exception and include a custom constructor such that Exception.getMessage() returns a string specified in the constructor?
Or more generally, how do I pass arguments from my custom constructor to the base constructor in Apex?