Packagecom.test;ImportJava.io.FileReader; Public classTest2 { Public Static voidMain (string[] args)throwsException {Father Father=NewFather (); Father.test1 (); Father.test2 (); }}classfather{PrivateSon son =NULL; PublicFather () { This. son =NewSon (); } Public voidtest1 () {System.out.println ("1"); //to tune son's Test2, you have to capture or throw a layer of the top and throw it to the virtual machine. Try{son.test2 (); } Catch(Exception e) {//Todo:handle ExceptionSystem.out.println ("Give an exception to the previous caller to handle"); System.out.println ("Father's in the process."); E.printstacktrace (); } } //or no matter whether the layer is throws upward, a layer of upward throw, run to the main function eventually thrown to the JVM virtual machine Public voidTest2 ()throwsException {System.out.println ("1"); //to tune son's Test2, you have to capture or throw a layer of the top and throw it to the virtual machine.Son.test2 (); }}classson{ Public voidTest2 ()throwsException {FileReader fr=NULL; Fr=NewFileReader ("D:\\aa.txt"); }}
Java exception handling throws throws exception