Reputation: 15
package com.psl.exception;
public class NoDataFoundException extends Exception {
public NoDataFoundException(){
super("No Data Found");
}
public NoDataFoundException(String msg){
super(msg);
}
}
What does the class Exception do with the string that is passed? I tried it and it does nothing. What is the point of passing the string to the constructor of Exception then?
Upvotes: 0
Views: 2097
Reputation: 3625
One of the constructors of Exception takes a string to use as the detail message.
See here: http://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html
The default constructor uses a null detail message, but other components such as a message and throwable can be specified
Upvotes: 0
Reputation: 1074266
The documentation says:
Constructs a new exception with the specified detail message.
The detail message is available from getMessage
and usually included in toString
and such.
Upvotes: 1
Reputation: 240900
It sets String
passed as message in Throwable
, which is generally a useful custom message which gets printed when exception is thrown, also can be retrieved by getMessage()
method on Throwable
Upvotes: 1