The standard Exception has no default constructor (or a way to set the message after instantiation). If a custom exception is based on it, can the derived class be made injectable?
public class SpecialPurposeException extends Exception {
private static final long serialVersionUID = 1L;
public SpecialPurposeException(String message) {
super(message);
}
}
The custom exception will not normally be instantiated outside of its module, but for consistency reasons it should perhaps be injected inside of it.
There is a no-args for
Exception. SeeException().You cannot modified the value of the message
StringinException, but you can override thegetMessage()method to return something different. That should be sufficient to allow you to inject a message … in various ways.