
JAVASE学习笔记 (十)(异常)
发布日期:2021-05-14 17:01:34
浏览次数:17
分类:精选文章
本文共 4365 字,大约阅读时间需要 14 分钟。
Java������������������
������������������
Java������������������������������������������������Throwable
���������������������������������Java API������������������������������������������������������������������������
Error
���Java���������������������������������������������������������������������������������������������������Error���������
- ���������������������
OutOfMemoryError
���VirtualMachineError
���������������JVM��������������������� - ���������������������
NoClassDefFoundError
���LinkageError
������������������������������������������
Exception
������������������������������������������������������������RuntimeException
������������������������������
ArrayIndexOutOfBoundsException
������������������NullPointerException
���������������������ArithmeticException
������������������������MissingResourceException
������������������ClassNotFoundException
������������������ ������������������������������������������Unchecked Exception������������������������������������������������������
Error���Exception���������
- Error���������������������������������������JVM������������������������
- Exception������������������������������������������������������������������������������������������������������������������
������������������
������������������������������������������������������
- try������������������������������������������������
- catch���������������������������������������������������
- finally���������������������������������������������������
- throw������������������������������
- throws���������������������������������������������������������������
throw���throws���������
- throw���������������������������������������������JVM���������
- throws������������������������������������������������������������������
������Error
Error���������JVM������������������������������������������������������������������
���������������
public class StackOverflow { public static void main(String[] args) { new StackOverflow().test(); } private void test() { try { test(); } catch (StackOverflowError e) { System.out.println("���������"); } }}
���������������StackOverflowError: Stack overflow
���������������������������������
- ���������������������������������������������������������������
throws
��������� - ������������������������������������������������������������������
RuntimeException
���
������������������������
public class CustomeException { public static void main(String[] args) { try { int result = m1(999); System.out.println("result: " + result); } catch (MyException e) { System.out.println("���������������������"); } } public static int m1(int num) { if (num % 2 == 0) { throw new MyException("���������������"); } return num + 100; }}class MyException extends RuntimeException { public MyException(String message) { super(message); }}
������������������
public class Demo09 { public static void main(String[] args) { try { int num = new Random().nextInt(10); if (num < 4) { throw new NullPointerException("������������"); } System.out.println("������������"); } catch (NullPointerException e) { System.out.println("���������������"); } }}
���������������
class MyException extends RuntimeException { public MyException(String message) { super(message); }}public class Demo12 { public static void main(String[] args) { try { int num = new Scanner(System.in).nextInt(); isEven(num); System.out.println("������"); } catch (MyException e) { System.out.println(e.getMessage()); } } public static void isEven(int num) throws MyException { if (num % 2 == 0) { throw new MyException("������"); } }}
������
- ���������������������������������������������������
- ������catch������������������������������
- ** finally������������������**������������ releasing.
- ������������������������������������������������������������
- ���������������������������������������������������������������.
������������printStackTrace()
���������������������������������������������������������������������������������������������������
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月19日 11时13分58秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
n的a进制数
2021-05-15
配置jdk的环境变量
2021-05-15
【C++ Primer 第五版】处理类型
2021-05-15
echo命令的颜色及同行显示控制
2021-05-15
CentOS7利用Systemd添加用户自定义系统服务
2021-05-15
懒人HTML5笔记-1
2021-05-15
两台服务器http方式共享yum软件仓库
2021-05-15
团队背包(team)
2021-05-15
java字节流与字符流的区别
2021-05-15
Mysql 批量杀死进程
2021-05-15
spring tx:advice 和 aop:config 配置事务
2021-05-15
修改layui的后台模板的左侧导航栏可以伸缩
2021-05-15
Mybatis Generator最完整配置详解
2021-05-15
报错:For input string
2021-05-15
ThreadLocal源码分析解密
2021-05-15
【Java并发编程】并发编程大合集
2021-05-15
Ubuntu初始化root密码
2021-05-15
编译android源代码(aosp)
2021-05-15
verilog一些小知识点注意事项集合
2021-05-15