Extending Exception and Overloading constructors.
public class SomeException extends Exception {
public SomeException () {
super ("exc");
}
public SomeException (String message) {
super (message);
}
}
Is this one needed? Why?
public SomeException (String message) {
super (message);
}
In Exception class, there are various constructors to build a new instance of Exception class. So in the above code, constructor with a String parameter is overloaded the Exception's String constructor.
Why overload Exception Constructor?
If you want to throw a your exception with a String message, you can create a constructor with a String parameter. Calling the super(message) in the above code, that redirect the message to Exception class's constructor with the String parameter.
If you don't want any message to identify the error or any detail, you don't want to create that extra constructor.
No comments:
Post a Comment