Exception User
# Java Example - Custom Exceptions
[ Java Examples](#)
The following example demonstrates how to create custom exceptions by extending the Exception class:
## TestInput.java File
class WrongInputException extends Exception{// Custom class WrongInputException(String s){super(s); }}class Input{void method()throws WrongInputException{throw new WrongInputException("Wrong input"); // Throw custom exception}}class TestInput{public static void main(String[]args){try{new Input().method(); }catch(WrongInputException wie){System.out.println(wie.getMessage()); }}}
The output of the above code is:
Wrong input
[ Java Examples](#)
YouTip