JAVA try&&catch

package z;

public class Test4_5 {
	static void Proc(int sel) {
		try {
			if (sel != 0) {
				System.out.println("no Exception ");
				//return;
			} else {
				int j = 4 / sel;
			}
		}catch (ArithmeticException e) {
			System.out.println("Catch ");
		} catch (Exception e) {
			System.out.println("Will not be executed");
		} finally {
			System.out.println("finally");
		}
	}

	public static void main(String args[]) {
		Proc(0);
		Proc(2);
	}
}

需要首先注意的几点:

     1) try catch finally中的finally不管在什么情况之下都会执行,执行的时间是在程序return 之前.

     2) Java 编译器不允许有显示的执行不到的语句块,比如return之后就不可能再有别的语句块(分支不属于此列) 




原文地址:https://www.cnblogs.com/lgh1992314/p/5835220.html