编程语言
首页 > 编程语言> > Java 异常之:三步走

Java 异常之:三步走

作者:互联网

	static void try_catch_finally_demo() {
		{//Java 异常之:三步走
			int opt = 1;
			if (opt == 1) {
				try {
				} finally {
					//wrong! should catch exception!
				}
			} else if (opt == 2) {
				try {
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					//wrong! should catch Throwable! 
					//eg. StackOverflowError
				}
			} else if (opt == 3) {
				try {
				} catch (Throwable e) {
					e.printStackTrace();
				} finally {
					//good, every Error.class will be catch!
				}
			}
			//编程工具之函数查找:http://mathy.xyz/findFun.htm
		}
	}

 

willy2 发布了23 篇原创文章 · 获赞 5 · 访问量 3万+ 私信 关注

标签:opt,Java,三步走,try,printStackTrace,finally,catch,异常
来源: https://blog.csdn.net/willy2/article/details/104450393