-
java异常处理
3.8 异常处理
什么是异常
知道Java异常分类
处理异常的两种方式
throw和throws区别
如何创建自定义异常
概念:
在程序中,可能产生程序员没有预料到的各种错误情况,比如打开一个不存在的文件等,在Java中,这种在程序运行时可能出现的错误称为异常。
异常可以把“描述在正常执行过程中做什么事”的代码和“出了问题怎么办”的代码相分离
例子:demo05.ExceptionDemo.java
Java异常分类A:
java.lang.Error,java.lang.Exception
Error(错误):jvm系统内部错误、资源耗尽等严重问题,发生Error时,编程人员无能 为力,只能终止程序,例如内存溢出等。
Exception(异常):因编程错误或偶然的外在因素导致的一般性问题,例如:对负数 开平方根、空指针访问等,当发生Exception 时,编程人员可以做出处理,并做出人性 化响应,比如弹出窗口,显示“请不要输入负数!”。
异常分类B:
检查性异常:编译器必须处理的异常,该类异常通常是Exception类型或其子类(RuntimeException类除外)//运行时异常
SQLException、IOException、ClassNotFoundException
例子:/DemoProject/src/com/hyg/demo08/FileInputStreamDemo.java
非检查性异常:编译器不要求强制处理的异常,RuntimeException类及其所有子类都是非检查性异常。
NullPointerException、ClassCastException
例子:equa
- 2022-02-14 14:02:16下载
- 积分:1
-
autocad second development, on the basis of visual basic and vba
autocad二次开发,基于visual basic 和vba的-autocad second development, on the basis of visual basic and vba
- 2022-12-01 10:05:03下载
- 积分:1
-
此源程序演示了在新式,PDA上如何正确显示汉字。
此源程序演示了在新式,PDA上如何正确显示汉字。
- 2023-02-23 08:05:04下载
- 积分:1
-
VB series, the flower procedures, which are incomplete, and can change their own...
VB编的电子琴程序,内容不完整,可以自己改成自己的软件-VB series, the flower procedures, which are incomplete, and can change their own software
- 2022-08-13 06:47:42下载
- 积分:1
-
iphone程序,让本地应用程序打开URL链接,31天开源工程中的第三个。...
iphone程序,让本地应用程序打开URL链接,31天开源工程中的第三个。-openURL helps you launch Maps, SMS, Browser, Phone, and even other applications. This is one area of iPhone development that I always have to look up again when I need to do it and it is only one line!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]]
This app demonstrates the basic protocols supported natively on the phone.
- 2022-10-08 13:15:02下载
- 积分:1
-
把文本转换成pdf文件,是学习pdf编成的基础知识
把文本转换成pdf文件,是学习pdf编成的基础知识-put text into pdf documents into pdf study of the basic knowledge
- 2023-03-09 20:25:02下载
- 积分:1
-
基于Delphi的前景产生的BOM树结构的递归过程
基于Delphi的,用于前台产生BOM树状结构的递归过程-based Delphi, prospects for the tree structure generated BOM recursive process
- 2022-02-26 15:05:40下载
- 积分:1
-
sadfasdfplease阅读您的文件包和描述它的英语…至少40字节
sadfasdfPlease read your package and describe it at least 40 bytes in English.
System will automatically delete the directory of debug and release, so please do not put files on these two directory.
- 2022-06-30 04:36:24下载
- 积分:1
-
VC开发一个桌面弹子球游戏源程序,欢迎各位共享
VC开发一个桌面弹子球游戏源程序,欢迎各位共享-development of a desktop VC billiard ball game source, welcome you to share
- 2022-10-04 09:05:03下载
- 积分:1
-
图形化界面的五子棋游戏,可以两人对战下,也可以挑战AI的
图形化界面的五子棋游戏,可以两人对战下,也可以挑战AI的-Graphical interface Gobang game, you can both play, they can challenge the AI
- 2022-03-30 14:15:04下载
- 积分:1