YouTip LogoYouTip

Exception User

# Java Example - Custom Exceptions [![Image 3: Java Examples](#) 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 [![Image 4: Java Examples](#) Java Examples](#)
← Data StackString Concatenation β†’