2024年3月26日发(作者:)
可编辑修改
java异常(习题)
Key Point
* 异常的概念和分类
* 异常的产生和传递
* 异常的处理
* 自定义异常
练习
1. 填空
Java 中所有的错误都继承自______类;在该类的子类中,
_______类表示严重的底层错误,对于这类错误一般处理的方式是___________;
_______类表示例外、异常。
2. 查api,填空
异常类yBoundException,从分类上说,该类属于__________(已检查|
未检查)异常,从处理方式上说,对这种异常___________________;
异常类nSyntaxException,从分类上说,该类属于_________(已检
查|未检查)异常,从处理方式上说,对这种异常__________________。
3. (异常的产生)把下面代码补充完整
package exception;
public class TestThrow {
}
public static void throwException(int n) {
}
if (n == 0) {
}
// 抛出一个NullPointerException
// 抛出一个ClassCastException
// 并设定详细信息为“类型转换出错”
} else {
public static void main(String args[]) {
}
throwException(10);
4. (try-catch-finally)有如下代码:
import .*;
精选doc
可编辑修改
import .*;
class TestException {
public static void main(String args[]) {
n("main 1");
int n;
// 读入n
ma(n);
n("main2");
}
public static void ma(int n) {
try {
n("ma1");
mb(n);
n("ma2");
} catch (EOFException e) {
n("Catch EOFException");
} catch (IOException e) {
n("Catch IOException");
} catch (SQLException e) {
n("Catch SQLException");
} catch (Exception e) {
n("Catch Exception");
} finally {
n("In finally");
}
}
public static void mb(int n) throws Exception {
n("mb1");
if (n == 1)
throw new EOFException();
if (n == 2)
throw new FileNotFoundException();
if (n == 3)
throw new SQLException();
if (n == 4)
throw new NullPointerException();
n("mb2");
}
}
问:当读入的n 分别为1,2,3,4,5 时,输出的结果分别是什么?
精选doc


发布评论