![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
异常
Logodad
这个作者很懒,什么都没留下…
展开
-
2020-08-22 Java异常处理通过5个关键字控制:try、catch、throw、throws和 finally
下面讲述它们如何工作的。 ①程序声明了你想要的异常监控包含在一个try块中。如果在try块中发生异常,它被抛出。 ②你的代码可以捕捉这个异常(用catch)并且用某种合理的方法处理该异常。系统产生的异常被Java运行时系统自动抛出。 ③手动抛出一个异常,用关键字throw。任何被抛出方法的异常都必须通过throws子句定义。 ④任何在方法返回前绝对被执行的代码被放置在finally块中。 一、try 将可能发生异常的代码块用try包裹,一旦发生异常,转到catch块。一旦执行了catch语句,程序控原创 2020-08-22 14:38:02 · 1197 阅读 · 0 评论 -
2020-02-22 使用Java创建自己的异常子类
先贴一段代码 // This program creates a custom exception type. class MyException extends Exception { private int detail; MyException(int a) { detail = a; } public String toString() { return "MyException[" + detail + "]"; } } c原创 2020-08-22 11:36:37 · 124 阅读 · 0 评论