在异常处理中,如释放资源、关闭文件、关闭数据库等由()子句来完成。
A. try
B. catch
C. finally
D. throw
查看答案
finally块中的代码将()。
A. 总是被执行
B. 如果try块后面没有catch块时,finally块中的代码才会执行
C. 异常发生时才被执行
D. 异常没有发生时才被执行
假设有以下代码:try{tryThis( );return;}catch(IOException x1){System.out.println("exception 1");return;}catch(Exception x2){System.out.println("exception 2");return;}finally{System.out.println("finally");}如果tryThis( )抛出NumberFormatException,则输出结果为()。
A. 无输出
B. "exception 1",后跟"finally"
C. "exception 2",后跟"finally"
D. "exception 1"
E. "exception 2"
假设有以下代码段:#01String s = null;#02if( s != null & s.length( ) > 0 )#03System.out.println("s != null & s.length( ) > 0" );#04if( s!= null && s.length( ) > 0 )#05System.out.println("s != null && s.length( ) > 0" );#06if( s!= null || s.length( ) > 0 )#07System.out.println("s != null || s.length( ) > 0" );#08if( s!= null | s.length( ) > 0 )#09System.out.println("s != null | s.length( ) > 0" );将抛出空指针异常的行是()。
A. 2、4
B. 6、8
C. 2、4、6、8
D. 2、6、8
关于抛出异常的描述,错误的是()。
A. 任何从Throwable派生的类都可以用throw语句抛出
B. Exception和Error是Throwable的直接派生类
C. 异常抛出点后的代码在抛出异常后不再执行
D. Exception代表系统严重错误,一般程序不处理这类错误