网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
下列关于throws和throw描述有误的是
A.throw用在方法后面,跟的是类名,throws用在方法体内,跟的是异常对象名
B.throw只能抛出一个对象名,throws后面可以跟多个类名
C.throw表示异常对象,由方法体内的语句处理,throws表示表示抛出类型,由调用者处理
D.throw执行时表示一定是抛出了某种异常,throws执行时表示出现异常的 一种可能性
参考答案和解析
throw用在方法后面,跟的是类名,throws用在方法体内,跟的是异常对象名
更多 “下列关于throws和throw描述有误的是A.throw用在方法后面,跟的是类名,throws用在方法体内,跟的是异常对象名B.throw只能抛出一个对象名,throws后面可以跟多个类名C.throw表示异常对象,由方法体内的语句处理,throws表示表示抛出类型,由调用者处理D.throw执行时表示一定是抛出了某种异常,throws执行时表示出现异常的 一种可能性” 相关考题
考题
给出下列的不完整的方法,则下列的( )声明可以被加入①行完成此方法的声明。 ① ②{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.Ⅰ、Ⅳ
考题
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.
考题
下列关于异常的描述正确的是()A、在C#中一个try块只能有一个catch块B、一个try块可能产生多个异常C、可以使用throws回避方法中的异常D、finally块是异常处理所必需的
考题
现有: 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.
考题
单选题假设有自定义异常类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.
考题
单选题下列关于异常的描述正确的是()A
在C#中一个try块只能有一个catch块B
一个try块可能产生多个异常C
可以使用throws回避方法中的异常D
finally块是异常处理所必需的
考题
单选题现有: 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
热门标签
最新试卷