Java Exception Handling Mechanism throw throws custom business logic exception throws continue to throw catch capture will automatically continue to throw the call method, throwthrows
Package com. swift; public class Exception_TestC {public static void main (String [] args) {/** 5th question: one class is ClassA and one class is ClassB, there is a method B in ClassB. This method throws an exception. There is a * method a in the ClassA class. Please call B in this method and then throw an exception. There is a class TestC on the client, and there is a method of c. Capture exception information in this method. Java Exception Handling Mechanism ** if return exists in a try or catch, execute try catch finally return. If catch is executed, check whether an exception exists in a try. * throw throws and declares an exception, throw is used in the method body to throw an actual exception object. After throw is used, either try * catch is used to catch an exception or throws is used to declare an exception. In the catch, throw can throw an exception again, so that you can call the method to catch and handle the * custom exception used to mark the exception of the business logic to avoid confusion with the standard exception */new TestC (). c () ;}} class A {public void a () throws Exception {new B (). B () ;}} class B {public void B () {try {int a =-1; if (a <0) {throw new MyException ("B .... negative numbers cannot be used .. throw by ClassB. methodB ") ;}} catch (MyException e) {e. printStackTrace () ;}} class TestC {public void c () {try {new (). a ();} catch (Exception e) {e. printStackTrace () ;}} class MyException extends Exception {public MyException (String msg) {super (msg );}}