网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
单选题
throw和throws的说法不正确的是()
A
throw是方法内抛出异常
B
throws是方法声明是抛出异常
C
throw可以抛出多个异常
参考答案
参考解析
解析:
暂无解析
更多 “单选题throw和throws的说法不正确的是()A throw是方法内抛出异常B throws是方法声明是抛出异常C throw可以抛出多个异常” 相关考题
考题
给出下列的不完整的方法,则下列的( )声明可以被加入①行完成此方法的声明。 ① ②{success=connect(); ③if(success==-1){ ④throw new TimedOutException(); ⑤} ⑥}A.public void method()B.public void method()throws ExceptionC.public void method()throw TimedOutExceptionD.publicthrowTimedOutExceptionvoidmethod()
考题
下列哪个选项不是InputStream类中的方法?A.public abstract int read()throws IOExceptionB.public final void writeInt (int v)throws IOExceptionC.public void close()throws IOExceptionD.public int available() throws IOException
考题
下列______选项不是InputStream类中的方法。A.public abstract int read() throws IOExceptionB.public final void writeInt (int V)throws IOExceptionC.public int available() throws IOExceptionD.public void close() throws IOException
考题
给出下列的不完整的方法,则下列的哪个声明可以被加入①行完成此方法的声明? ① ② { success = connect( ); ③ if (success = = - 1 ) { ④ throw new TimedoutException( ) ⑤ } ⑥ }A.public void method( )B.public void method( ) throws ExceptionC.public void method( ) throw TimedoutExceptionD.public throw TimedOutException void method( )
考题
给出下列的不完整的方法,则哪个声明可以被加入①行完成此方法的声明?( ) ① ② {success=connect(); ③ if(success==-1){ ④ throw new TimedOutException(); ⑤ } ⑥ }A.public void method()B.public void method()throws ExceptionC.public void method()throw TimedOutExceptionD.public throw TimedOutException void method()
考题
下列关于throws关键字的描述中正确的是()
A、thorws可以声明在方法上也可以声明在方法体中B、方法上使用throws抛出一个异常则这个方法中一定有trycatch代码块C、使用throws抛出多个异常时各个异常之间必须使用逗号隔开D、throws必须和throw配合使用
考题
下面的代码中方法unsafe()有异常发生,那么可以加在第一行的语句为( )。 { if(unsafe()) { //do something } else if(safe()) { //do the other) } Ⅰ:public void methodName() Ⅱ:public void methodName() throw IOException Ⅲ:public void methodName() throws IOException Ⅳ:public void methodName() throws ExceptionA.Ⅲ、ⅣB.Ⅱ、Ⅲ、ⅣC.Ⅰ、ⅢD.Ⅰ、Ⅳ
考题
static void test() throws RuntimeException { try { System.out.print(”test “); throw new RuntimeException(); } catch (Exception ex) { System.out.print(”exception “); } } public static void main(String[] args) { try { test(); } catch (RuntimeException ex) { System.out.print(”runtime “); } System.out.print(”end “); } What is the result?() A、 test endB、 Compilation fails.C、 test runtime endD、 test exception endE、 A Throwable is thrown by main at runtime.
考题
关于异常,以下说法正确的有()。A、运行时异常使用Runtime Exception的子类来表示,不用在可能抛出异常的方法声明上加throws子句B、运行时异常使用Runtime Exception的子类来表示,必须在可能抛出异常的方法声明上加throws子句C、非运行期异常是从Exception继承而来的,必须在方法声明上加throws子句D、非运行期异常是从Exception继承而来的,不需要在方法声明上加throws子句
考题
public class Test { public static void aMethod() throws Exception { try { throw new Exception(); } finally { System.out.println(“finally”); } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) { System.out.println(“exception”); } System.out.println(“finished”); } } What is the result?() A、 finallyB、 exception finishedC、 finally exception finishedD、 Compilation fails.
考题
现有: void topGo() { try { middleGo(); } catch (Exception e) { System.out.print("catch"); } } void middleGo() throws Exception { go(); system.out.print("late middle"); } void go() throws ExceptiOn { throw new Exception(); } 如果调用 topGo () ,则结果为:() A、 late middleB、 catchC、 late middle catchD、 catch Iate middle
考题
假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?() A、 raise ServiceExceptionB、 throw new ServiceException()C、 throw ServiceExceptionD、 throws ServiceException
考题
多选题Class TestException 1. public class TestException extends Exception { 2. } Class a: 1. public class a { 2. 3. public String sayHello(String name) throws TestException { 4. 5. if(name == null) { 6. throw new TestException(); 7. } 8. 9. return “Hello “+ name; 10. } 11. 12. } A programmer wants to use this code in an application: 45. A a=new A(); 46. System.out.println(a.sayHello(”John”)); Which two are true?()AClass a will not compile.BLine 46 can throw the unchecked exception TestException.CLine 45 can throw the unchecked exception TestException.DLine 46 will compile if the enclosing method throws a TestException.ELine 46 will compile if enclosed in a try block, where TestException is caught.
考题
单选题public class Test { public static void aMethod() throws Exception { try { throw new Exception(); } finally { System.out.println(“finally”); } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) { System.out.println(“exception”); } System.out.println(“finished”); } } What is the result?()A
finallyB
exception finishedC
finally exception finishedD
Compilation fails.
考题
单选题假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?()A
raise ServiceExceptionB
throw new ServiceException()C
throw ServiceExceptionD
throws ServiceException
考题
单选题What is wrong with the following code?() class MyException extends Exception {} public class Qb4ab { public void foo() { try { bar(); } finally { baz(); } catch (MyException e) {} } public void bar() throws MyException { throw new MyException(); } public void baz() throws RuntimeException { throw new RuntimeException(); } }A
Since the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in its throws clause.B
A try block cannot be followed by both a catch and a finally block.C
An empty catch block is not allowed.D
A catch block cannot follow a finally block.E
A finally block must always follow one or more catch blocks.
考题
单选题static void test() throws Error { if (true) throw new AssertionError(); System.out.print(”test “); } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print(”exception “); } System.out.print(”elld “); } What is the result?()A
endB
Compilation fails.C
exception endD
exception test endE
A Throwable is thrown by main.F
An Exception is thrown by main.
考题
单选题现有: void topGo() { try { middleGo(); } catch (Exception e) { System.out.print("catch"); } } void middleGo() throws Exception { go(); system.out.print("late middle"); } void go() throws ExceptiOn { throw new Exception(); } 如果调用 topGo () ,则结果为:()A
late middleB
catchC
late middle catchD
catch Iate middle
热门标签
最新试卷