/*
How to handle exceptions at the time of Detection:
1, not only in the function of the Declaration, but also in the function of the catch, the exception to deal with the problem;
2, only declare on the function, do not handle inside the function, at this time the exception is thrown to the virtual machine, at runtime or an exception occurs.
3, if the exception is resolved inside the function, it is no longer necessary to declare the function.
*/
/*
The exception is reflected in the child parent class overlay:
1, when the subclass overrides the parent class, if the method of the parent class throws an exception, then the child class's overriding method can only throw the exception of the parent class or the subclass of the exception.
2, if the parent method throws more than one exception, the child class can only throw a subset of the parent exception when overwriting the method.
3, if no exception is thrown in the method of the parent class or interface, then the subclass cannot throw an exception when overriding the method.
If a subclass method has an exception, it must be done with a try and never thrown.
*/
/*
Exceptions in this program:
Exception
|--fushuexception
|--subfushuexception
|--otherexception
*/
Class Fushuexception extends Exception{fushuexception (String msg) {super (MSG);}} Class Subfushuexception extends Fushuexception{subfushuexception (String msg) {super (MSG);}} Class Otherexception extends Exception{otherexception (String msg) {super (MSG);}} Class Fudemo{public int div (int a) throws Subfushuexception{if (a<0) throw new Subfushuexception ("There is a negative case.") "); return A;}} Class Demo extends fudemo{public int div (int a,int b) throws Subfushuexception{if (b<=0) throw new Subfushuexception ("appears "); return a/b;}} Class Exceptiondemo5{public static void Main (String args[]) throws Fushuexception{demo d=new Demo (); Try{int X=d.div (4,-1 ); SYSTEM.OUT.PRINTLN (x);} catch (Fushuexception e) {System.out.println (e.tostring ());} Finally{system.out.println ("Over");}}}
Java Exception Five