1. Code
Public classExceptest {/** * @paramargs*/ Public Static voidMain (string[] args) {System.err.println ("111111111111");//say (); //throws an exception, but the code does not display the try: Catch.. //Calc ();//throws an exception, but the code does not display the try: Catch.. //try {//Show ();//} catch (Exception e) {//e.printstacktrace ();//System.err.println ("Exception successfully captured: ");// } //try {//view ();//} catch (Exception e) {//e.printstacktrace ();//System.err.println ("Exception successfully captured: ");// }Calc22 (); System.err.println ("222222222222"); } Public Static voidSay () {//New NullPointerExceptionSystem.err.println ("say>>>>"); Throw NewNullPointerException (); } Public Static voidCalc () {//throws ArithmeticException, this exception is not prompted. System.err.println ("calc>>>>"); inti = 0, j = 0; System.err.println (i/j); } Public Static voidShow ()throwsexception{//this exception prompt. System.err.println ("show>>>>"); inti = 0, j = 0; System.err.println (i/j); } Public Static voidView ()throwsexception{System.err.println ("View>>>>"); Throw NewException (); } Public Static voidCalc22 () {System.err.println ("Calc22>>>>"); Try { inti = 0, j = 0; intK = i/J; } Catch(Exception e) {System.err.println ("Exception handling completed ...." ");//throw E; //The exception is thrown again. //throw new ArithmeticException (); //inherited from exception is a check-type exception (of course, runtimeexception itself is also a subclass of exception//throw new RuntimeException (); //(of course, runtimeexception itself is also a subclass of exception//Non-check exceptions that inherit from RuntimeException or error//ArithmeticException Inheritance RuntimeException} System.err.println ("Calc22>>>>calc22"); }}
2. Description
Using spring will inevitably use spring's transaction management, and it is natural to use transaction management to choose Declarative transaction management, in the spring documentation, spring declarative transaction management defaults to non-checked exceptions and runtime exceptions for transaction rollback, A rollback operation is not performed on a check-type exception.
So what is a check-type exception and what is a non-check exception?
The simplest point of judgment is two:
1. A non-check exception that inherits from RuntimeException or error, and inherited from exception is a check-type exception (of course, runtimeexception itself is also a subclass of exception).
2. The non-check type exception can not be captured, and the check type exception must be handled with a try statement block or the exception to the superior method processing, in short, must write code to deal with it.
Reference: http://blog.csdn.net/yixiaoqingyuz/article/details/4485606
Java-checked and non-checked exceptions