Custom exception,
// A custom exception must inherit a parent class indicating the exception, because the exception class and the exception object are thrown,
// Only the Throwable system exists. Therefore, only classes and objects in this system can be operated by throws and throws,
// Exception is a subclass of Throwable
Class MyException extends Exception {// custom Exception message Exception (String message) {super (message ); // call the constructor of the parent class} class Demo {int method (int x, int y) throws MyException // throw, declare on the function {judge if (x <0) throw new MyException ("write the exception information shown here") where a custom exception is thrown "); // manually throw a custom exception object through the throw keyword return x/y;} class ExceptionTest {// when throw throws an exception object in the function, you can either use try catch internally or declare it on the function so that the caller can handle public statc void main (String [] args) {Demo demo = new Demo (); try {int x = demo. method (4, 1);} catch (MyException e) {System. out. println (e. toString ());}}}