Monday, 13 May 2013

How to create user defined unchecked Exception

We have to create a class extending from RuntimeException like below.

Code
--------
public class InvalidInputException extends RuntimeException {

public InvalidInputException() {
super();
}

public InvalidInputException(String message) {
super(message);
}
}


As java.lang.Exception class is by deafult a  checked Exception class, the subclass we derive from this will be by default a checked Exception. If you want to make an unchecked exception class you have to create a class extending from java.lang.RuntimeException

No comments:

Post a Comment