11.1 recognize abnormal

Abnormality is due to an error in the program execution processing on the program logic leads to a program instruction stream is interrupted
Example: no abnormal code

public class JavaDemo {
	public static void main(String args[]) {
		System.out.println("【1】****** 程序开始执行 ******");
		System.out.println("【2】****** 数学计算:" + (10 / 2));		// 执行除法计算
		System.out.println("【3】****** 程序执行完毕 ******");
	}
}

Results of the

【1】****** 程序开始执行 ******
【2】****** 数学计算:5
【3】****** 程序执行完毕 ******

Example: an exception code

public class JavaDemo {
	public static void main(String args[]) {
		System.out.println("【1】****** 程序开始执行 ******");
		System.out.println("【2】****** 数学计算:" + (10 / 0));	// 执行除法计算
		System.out.println("【3】****** 程序执行完毕 ******");
	}
}

Results of the

【1】****** 程序开始执行 ******
Exception in thread "main" java.lang.ArithmeticException: / by zero
	at com.lxh.elevenchapter.java242.main(java242.java:8)

If not properly handle the exception, the program will execute an interruption, in order to let the program can still perform normal after an exception occurs, it must be introduced to improve exception handling code.

Published 162 original articles · won praise 9 · views 3092

Guess you like

Origin blog.csdn.net/ll_j_21/article/details/104711241