java入门之异常处理小结
(1)异常和错误
异常(Exception):不正常的事件,会中断程序,在运行中发生的意外,程序本身可以处理,防止程序中断;程序中会捕获的异常信息,并告诫用程序员,不要求程序必须对它做处理.catch完之后不作处理.
错误(Error):程序本身无法处理的.比如跟操作系统不兼容的问题.设计内存问题.,应用程序不应该抛出这类异常信息,这种错误程序员无法处理。
(2)异常的分类;
下图表示了异常类之间的关系.
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAG5CAIAAAD3aO7bAAAgAElEQVR4nO3dS7KyvBqG4T0Ce/7zseFobDgYy4F8TVpOwAlYtVbXAawJsBsQyOEFggZyuq+idv3bzwMr5vAYAvyvBQAACO1/sXcAAAAUiIQBAADCI2EAAIDwSBgAACA8EgYAAAiPhAEAAMIjYQAAgPBIGAAAIDwSBgAACI+EAQAAwiNhAACA8EgYAAAgPBIGAAAIj4QBAADCI2EAAIDwSBgAACA8EgYAAAgvTsL4d/iPLa8tSj0BAOSLhMHmtUWpJwCAfJEw2Ly2KPUEAJCvyAkjyqfDH98UAOAzJAzM4ZuKK/rcFRtbt8VuCsgSCQNz+Kbiij6usLF1W+ymgCyRMDCHbyqu6OMKG1u3xW4KyBIJA3P4puKi/BEXNRDfIGFgDt9UXJQ/4qIG4hskDMzhm4qL8kdc1EB8g4SBOXxTcVH+iIsaiG+QMDCHbyouyh9xUQPxDRIG5vBNxUX5Iy5qIL5BwsAcvqm4viv/5nk4ep2LeLr/Bd7xjTXXfs8vTexdKRw9AL5RXsLw61XpmPzQv8QVpPzfl75FPJ1a/3c7Z5kw2t/X6fjvcH79xN6R0tED4BvlJYzOXAf0vhxJGJ7oX+LaOmH0iTy/hIGd0APgGzUmjPbn/iBh+KF/iWv7hNH+3c6pJ4zmynRFLPQA+EaVCaNt3w0Jwwv9S1w7JIxofu4Pr9wQ/oDI+3J83H6DvV3R6AHwjUoTBjzRv8S1bcJort/GjmHF5eE/acw2F0WNE4fD4+fn5WytkdLfZ9hzoS3/3B+H47/D9W0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GxrbVFrt3iSmJQhjG++yGahLGGklUNgkJg42Nbastdu8SUzKFMM4x7HCp72BIGGskU9ls8RMGAJQntU5fW5GQwzJGEsYaqVW2AQkDAMJLttPPgHizEkxLtrKRMAAgvGQ7fZQn2cpGwgCA8JLt9FGeZCsbCQMAwku200d5kq1sJAwACC/ZTh/lSbaykTAAILxkO32UJ9nKRsIAgPCiX4yErcItdq23kTAAILzogw1bhVvsWm8jYQBAeNEHG7YKt9i13kbCAAAA4ZEwAABAeCQMAAAQHgkDAACER8IAAADhkTAAAEB4JAwAABAeCQMAAIRHwgAAAOGRMAAAQHgkDAAAEB4JAwAAhEfCAAAA4ZEwAABAeCQMAAAQHgkDAACER8IAAADhkTAAAEB4JAwAABAeCQMAAIRHwgAAAOGRMAAAQHgkDAAAEN7/AV0GFd+Z0s4+AAAAAElFTkSuQmCC" alt="" width="485" height="299" />
所有的异常类的父类都是Exception,它有两大分支:检查异常类和非检查异常类(RuntimeException),
又称是编译器异常)和运行期异常(比如)。
编译器异常就是在编译器中敲代码时候的错误提示,如果不修改就没法运行这个程序。
运行期异常顾名思义就是程序编译通过,但是在输出时候发生异常,比如是在控制台输入时敲错了数字,导致进行运算时候发生错误;如进行除法运算,输入了0;
Exception一个重要的分支是runtimeexception,它是描述编程产生的错误,这种异常通常由JVM自动捕获并抛出,说明这段代码有问题.下面就要说明捕获到异常之后怎么处理.
(3)异常的处理;
将意外进行处理的语句;
1.Try-catch语句;
try-catch的语法格式如下:
Try { //可能发生的异常代码 } Catch { //捕捉到异常之后的对它的处理; }
(示例代码如下)
public class exceptiondemo { public static void main(String[] args) { int a=0;
int b=0;
try{ System.out.println(a/b); }
catch(Exception e)
{ e.printStackTrace();
//获取异常的堆栈信息
//可以自己定义捕捉异常之后输出的提示内容,让程序员更加明白发生了的什么异常;
System.out.println("除法运算出现异常"); } System.out.println("finish!"); }
}
try-catch语句的使用
运行结果;
除法运算出现异常
finish!
java.lang.ArithmeticException: / by zero
at day23_1027.exceptiondemo.main(exceptiondemo.java:11)
通过上面的代码以及运行结果发现:上面可以发现,catch捕捉到异常,但是并不会影响后面的语句执行,而如果没有用trycatch语句来获取异常信息,后面的代码并不会执行。
但是在程序中Try会抛出很多种类的异常(空指针,或者是数学运算的问题都有可能),这个时候不建议只用一个Exception来捕获各种异常,当有多个try catch语句的时候,程序会按顺序执行,这个时候父类异常Exception应该放在后面,子类的错误放在前面,当抛出的异常都不属于子类的异常,就由父类来捕获处理.就是说先小后大,先子类后父类.
public static void main(String[] args) { int a=2;
int b=1;
String c=null;
try{ System.out.println("a/b="+a/b);
int index=c.indexOf(0);
System.out.println(index);
}
catch(ArithmeticException e)
{ System.out.println("除数不能为0!!");
}
catch(NullPointerException e)
{ System.out.println("检测到空指针异常!!"); }
catch(Exception e)
{
System.out.println("检测到不知名异常!!");
} System.out.println("风雨不改还是运行完了"); }
}
多catch的使用
运行结果:
a/b=2
检测到空指针异常!!
风雨不改还是运行完了
当父类异常放在前面的时候,会有如下显示,可见在编译器中两个子类都有错误提示出现.(可在编译器中复制错误代码示例看编译器报错的提示)
一般一段代码可能有多种异常抛出时,不要把父类的异常放在前面。
ry{ System.out.println("a/b="+a/b); int index=c.indexOf(0); System.out.println(index); } catch(Exception e) { System.out.println("检测到不知名异常!!"); } catch(ArithmeticException e) { System.out.println("除数不能为0!!"); } catch(NullPointerException e) { System.out.println("检测到空指针异常!!"); }
错误代码示例
最后提示一点:
一个catch只会处理一个try的信息,不可一个try同时匹配到多个catch信息.(放在同一个try里面,不能同时检测到空指针同时又检测到除数不能为0),不同功能的代码就放在不同的try里面.
(2)Try-catch-finally 语句
在java中,Finally的作用是程序不管什么情况都会执行里面的代码,不管是否执行catch语句;对于大多数程序都是这样子。
但是也有唯一的情况————————
System.exit(1) //该语句意思是直接退出JAVA虚拟机
若程序中出现该语句,并且在finally语句之前,那么finally不会执行,这也是finally不执行的唯一情况;
下面通过实例来演示finally的作用:
public class exceptiondemo2 { public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=1;
int b=0;
String c=null;
try{ System.out.println("a/b="+a/b);
int index=c.indexOf(0);
System.out.println(index);
}
catch(ArithmeticException e)
{ System.out.println("除数不能为0!!");
}
finally{ System.out.println("(这是finally语句块)这是一定要执行的!!"); }
System.out.println("程序执行完了!!"); } }
finally的使用
(3)try-catch-finally 语句若try中&catch有returns的情况
完整try-catch-finally 若try中&catch有returns语句且先不将此返回给调用者,等finally执行完毕后返回return。
try...catch...finally...三个语句块中如果有return语句的执行顺序。
finally中有return用finally.return代替,顺序为:
“try语句 -> catch -> finally -> finally.return -> catch.return -> try.return”任何阶段的return被执行,则整个语句块结束。
二:小总结
(1)异常处理的流程:
try { //执行的代码,其中可能有异常。一旦发现异常,则立即跳到catch执行。否则不会执行catch里面的内容 }
catch { //除非try里面执行代码发生了异常,否则这里的代码不会执行 }
finally { //不管什么情况都会执行,包括try catch 里面用了return ,可以理解为只要执行了try或者catch,就一定会执行 finally }
所以通常都会用finally语句来进行资源的释放;比如涉及到数据库的使用好关闭,出现了异常立马关闭数据库.
(2)try-catch实际应用
对于不确定的代码,可以加上try-catch处理潜在的异常;
尽量去处理异常,最好不要只是简单的调用printStackTrace()去打印输出; 比如是在打印输出异常同时最好加点操作,比如是业务回滚;
具体怎么去处理异常,就要根据不同的业务需求和异常类型去决定,
有网络连接和连接数据库的历程,尽量去添加finally语句去释放占用的资源,在程序发生异常或者执行结束之后自动清理内存资源,减少系统负担。
java入门之异常处理小结的更多相关文章
- Java入门 异常处理
Java入门 异常处理 1.处理异常(try-catch以及try-catch-finally): a)try会抛出很多种类型的异常-多重catch块的处理 eg:try{ //一些会抛出异常的方法 ...
- 【Java入门提高篇】Day16 Java异常处理(上)
当当当当当当,各位看官,好久不见,甚是想念. 今天我们来聊聊Java里的一个小妖精,那就是异常. 什么是异常?什么是异常处理? 异常嘛,顾名思义就是不正常,(逃),是Java程序运行时,发生的预料之外 ...
- 【Java入门提高篇】Day16 Java异常处理(下)
今天继续讲解java中的异常处理机制,主要介绍Exception家族的主要成员,自定义异常,以及异常处理的正确姿势. Exception家族 一图胜千言,先来看一张图. Exception这是一个父类 ...
- Java入门教程十一(异常处理)
在程序设计和运行的过程中,发生错误是不可避免的.尽管 Java 语言的设计从根本上提供了便于写出整洁.安全代码的方法,并且程序员也尽量地减少错误的产生,但是使程序被迫停止的错误的存在仍然不可避免.为此 ...
- Java入门-浅析Java学习从入门到精通【转】
一. JDK (Java Development Kit) JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库 ...
- Java入门篇(六)——类和对象
写到这里终于写到了入门篇的最后一个知识点了.类和对象是Java中经常被提到的两个词汇,实际上可以将类看作对象的载体,它定义了对象所具有的功能.Java是面向对象的语言,因此掌握类与对象是学习Java语 ...
- java入门概念梳理总结
Java入门学习 简介 public class HelloWorld { public static void main(String []args) { System.out.println(&q ...
- 测试人员学Java入门指南
目标读者 本指南特别适合有Python基础的同学学习Java入门,对于没有任何编程经验的同学可能会存在困难. 为什么测试人员要学Java 选择Java,应该不错.TesterHome测试论坛知名大佬基 ...
- Java入门第一章
后天就是十一长假了,亲们准备好了去哪儿玩了吗? 今天有点空,就来聊聊Java吧,当然是一些Java入门知识了,网上有很多,这里我只是列举一些我自己学到的,感谢大家关注喵的博客这么久,也为大家带来点新知 ...
随机推荐
- HUD 2089 位数dp
/* 做的不多的位数dp 暴力的话 不知道多少组数据 会T 所以写dp 思路就和数学课本上那种“不超过xxx的x位偶数有几个” 这里可以类似的维护一个前缀和模样的东西(但又不同于前缀和) 状态:f[i ...
- Windows Azure上的Odoo(OpenERP)-2.在Ubuntu虚拟机上部署Odoo(OpenERP)
创建虚拟机的步骤在这里就不再赘述了,请参考上一篇博文. 首先用下述命令将Ubuntu系统进行更新: 1. sudo apt-get update 2. sudo apt-get upgrade 3. ...
- (转)PHP函数spl_autoload_register()用法和__autoload()介绍
转--http://www.jb51.net/article/29624.htm 又是框架冲突导致__autoload()失效,用spl_autoload_register()重构一下,问题解决 ...
- word2vec生成词向量原理
假设每个词对应一个词向量,假设: 1)两个词的相似度正比于对应词向量的乘积.即:$sim(v_1,v_2)=v_1\cdot v_2$.即点乘原则: 2)多个词$v_1\sim v_n$组成的一个上下 ...
- POJ3126 Prime Path (bfs+素数判断)
POJ3126 Prime Path 一开始想通过终点值双向查找,从最高位开始依次递减或递增,每次找到最接近终点值的素数,后来发现这样找,即使找到,也可能不是最短路径, 而且代码实现起来特别麻烦,后来 ...
- 【COGS 56】质数取石子
[问题描述] DD 和 MM 正在玩取石子游戏.他们的游戏规则是这样的:桌上有若干石子,DD 先取,轮流取,每次必须取质数个.如果某一时刻某一方无法从桌上的石子中取质数个,比如说剩下 0 个或 1 个 ...
- Linux硬盘命名和安装分区
硬盘命名: 硬盘命名基于文件,一般有如下文件方式: /dev/hda1 /dev/sdb3 具体含义如下: /dev:是所有设备文件存放的目录. hd和sd:他们是区别的前两个字母,代表该分区所在的设 ...
- js 得到当前季度
Date.prototype.getQuarter = function() { var month = this.getMonth(); if(month < 3) { return '第一季 ...
- php拦截器(魔术方法)
什么是PHP拦截器? 英文名称 “interceptor”,作用是 拦截 发送未定义的方法和属性的消息. 先看一段代码,定义了一个School类,实例化一个对象$obj,获取一个未定义的属性teach ...
- Firefox--Date.parse()
比较两个时间字符串的时间大小用到了Date.parse()这个静态方法. 火狐下:Date.parse("2014-07-05 22:05:05") 返回的是NaN. 其它浏览器: ...