有关throw和throws的说法中不正确的是()。A.throw后面加的是异常类的对象B.throws后面加的是异常类的类名C.throws后面只能加自定义异常类D.以上说法都不正确
有关throw和throws的说法中不正确的是()。
A.throw后面加的是异常类的对象
B.throws后面加的是异常类的类名
C.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()
把一个对象写到一个流中相对比较简单,具体是通过调用ObjectOutputStream类的writeObject()方法实现的,那么该方法的定义为( )。A.public final int writeObject(Object obj) throws IOExceptionB.public final void writeObject(Object obj) throws IOExceptionC.public Object writeObject(Object obj) throws IOExceptionD.public final Object writeObject(Object obj) throws IOException
下列哪个选项不是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.
现有: 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(); } }ASince the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in its throws clause.BA try block cannot be followed by both a catch and a finally block.CAn empty catch block is not allowed.DA catch block cannot follow a finally block.EA finally block must always follow one or more catch blocks.
单选题现有: 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