资源描述
习题
一、选择题
1.以下哪个是所有异常和错误的基类( )
A.Exception B.Throwable C.Error D.RuntimeException
2.以下哪个关键字用于抛出一个异常( )
A.throw B.thorwn C.throws D.cacth
3. 以下哪一个是用户定义的异常类的正确声明( )
A.Class A extends B{…}
B.Class A extends Exception{…}
C.Class A extends B implements Exception{…}
D.Class A extends extends Exception implements Exception {…}
4. 下列说法中错误的是( )
A.子类可以与超类方法抛出相同类型的异常;
B.子类可以抛出超类方法所抛出的异常的子类;
C.子类中的方法抛出的异常数目可以少于超类中方法所抛出的异常数目,或者不需要抛出任何异常。
D.自定义异常不一定要继承Exception 及其子类;
5.下列说法中错误的是( )
A.try、catch、finally这三个关键字都不能单独使用。
B.try语句finally组成try...finally结构。
C.catch语句可以有一个或多个。
D.finally 语句可以有一个或多个。
二、填空题
1.Throwable类有两个直接类:___________指JVM系统内部错误、资源耗尽等严重情况;_____ 指其它因编程错误或偶然的外在因素导致的一般性问题。
2. 在Exception类中,返回当前异常对象信息的描述的方法是_______________;返回当前异常对象信息的详细描述的方法是:_____________;用来跟踪异常事件发生时执行堆栈的内容的方法是______________.
3. 如果Java运行时系统找不到可以捕获异常的方法,则运行时系统将终止,相应的Java程序也将________。
4. 在Java中用关键字_____________声明抛出的异常。
5. 无论是否抛出异常都要执行的语句应用放到_________语句中。
三、思考题
1.关键字throw的作用是什么?关键字throws的作用是什么?
2.假设statement2引起以下try-catch代码块的异常。
try {
statement1;
statement2;
statement3;
}catch(Exception1 e1){}
catch(exception2 e2){}
statement4;
回答以下问题:
(1) statement3将被执行吗?
(2) 如果没有捕获异常,还执行statement4吗?
(3) 如果在catch子句中捕获到异常,statement4将被执行吗?
3.假设statement2引起以下try-catch代码块的异常。
try{
statement1;
statement2;
statement3;
}catch(Exception1 e1){}
catch(exception2 e2){}
catch(exception3 e3){throw e3;}
finally{ statement4;}
Statement5;
回答以下问题:
(1) 如果没有捕获异常,还执行statement5吗?
(2) 如果异常类型是statement3,statement4执行吗?statement5将被执行吗?
4.下列代码的会出现什么问题?
class test{
public static void main(String args[]){
try{
int a=Integer.parseInt(args[0]);
int b=0;
int c =a/b;
}
catch(Exception ex){.....}
catch(RuntimeException ex){.....}
}
}
展开阅读全文