Exception(基础问题记录一下)
2018-03-17 22:40
393 查看
package com.test; import java.io.IOException; public class ExceptionTest { public static void main(String[] args){ System.out.print("E");//这里因为是顺序执行,所以肯定会输出 try { System.out.print("F");//这里因为是顺序执行,所以肯定会输出 badMethod(); System.out.print("A");//这里因为上一步抛出异常了,所以不可以执行 }catch (RuntimeException e){//NullPointerException System.out.print("B");//这里因为try中捕获异常了,所以输出了 }finally { System.out.print("C"); } System.out.print("D");//这里因为是顺序执行,所以肯定会输出 } public static void badMethod(){ throw new ClassCastException(); /*try { //如果这里是运行时异常,而上面捕获的只是其中一个小的异常,那么就会抛出异常,反之可以 //如果这里是运行时异常,上面是非运行时异常,编译也不会通过 throw new IOException();//如果这里是非运行时异常,而主函数是运行时异常,也不会抛异常,因为非运行异常这里已经捕获了,而上面的运行时异常没发生所以没捕获。 } catch (IOException e) { //e.printStackTrace(); System.out.print("G"); }*/ //System.out.print("G"); } }
相关文章推荐
- 由三目运算符 == ? : 引起的一个问题,醉了,基础不过关。记录一下,比较简单的一个问题,只是为了记录一下
- 求List长度(基础问题记录一下)
- java 基础问题的一些处理,记录一下,持续更新呗
- 记录一个问题看得懂就帮忙解决一下
- 记录一下自己使用sed遇到的问题
- 安装Ubuntu时遇到的问题,做一个笔记记录一下
- 基础问题记录
- 【python篇】python基础之--基本问题记录
- 记录一下解决webdriver启动浏览器报“Unable to find a free port”问题的方法
- 记录一下 ionic3使用iframe 报地址安全性问题
- 记录一下接多盟SDK遇到的问题
- redis集群环境安装(参照redis中文官网,中间遇到了一些问题,so,记录一下)
- 最近学习过程中遇到的问题,记录一下
- 最近由于马虎导致内存越界,整整花费一整天时间来找问题。记录一下,以示警告!
- 最近用struts2,遇到几个出错时未能打log的问题,算是小细节吧,记录一下!写代码必须继续坚持良好习惯!
- org.springframework.orm.jpa.JpaSystemException问题记录
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException。问题记录
- ora -12514问题(刚才给一位网友解决的,记录一下)
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException。问题记录
- Android基础知识记录|面试常见问题:activity被回收,如何保存回收前的状态