关于异常捕获后程序的去向

今天在技术讨论群里谈到了关于异常的问题,对于 异常捕获后,不知道程序的何去何从。 感觉不是很熟,概念也很模糊,所以自己做了个demo来增强记忆一下。

public class ExceptionTest {

	/**
	 * @author zhao33699
	 */
	// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓********在捕获chufa3的异常后,chufa3终止,继续向下执行chufa1和chufa2↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			chufa3();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		chufa1();
		chufa2();
	}

	// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓********该方法,在内部抛出捕获异常后,该循环继续↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
	public static void chufa1() {
		for (int i = 0; i < 10; i++) {
			try {
				System.out.println(100 / i);
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
		}
		System.out.println("chufa1程序运行完毕");
	}

	// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
	// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

	// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓********该方法,在内部抛出捕获异常后,该循环终止↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
	public static void chufa2() {
		try {
			for (int i = 0; i < 10; i++) {
				System.out.println(100 / i);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		System.out.println("chufa2程序运行完毕");
	}

	// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
	// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

	// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓********该方法,在外部抛出捕获异常后,该方法终止↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
	public static void chufa3() throws Exception {

		for (int i = 0; i < 10; i++) {
			System.out.println(100 / i);
		}

		System.out.println("chufa3程序运行完毕");
	}
	// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
	// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
}


 还望大家不吝赐教……

猜你喜欢

转载自blog.csdn.net/zhaohefeijava/article/details/19615145
今日推荐