The following example demonstrates the implementation of custom exceptions by inheriting Exception:
/* author by w3cschool.cc TestInput.java */ class WrongInputException extends Exception { WrongInputException(String s) { super(s); } } class Input { void method() throws WrongInputException { throw new WrongInputException("Wrong input"); } } class TestInput { public static void main(String[] args){ try { new Input().method(); } catch(WrongInputException wie) { System.out.println(wie.getMessage()); } } }
The output result of running the above code is:
Wrong input
The above is the Java example - the content of the custom exception , for more related content, please pay attention to the PHP Chinese website (www.php.cn)!