更多“throw和throws的说法不正确的是()”相关问题
  • 第1题:

    给出下列的不完整的方法,则下列的哪个声明可以被加入①行完成此方法的声明? ① ② { success = connect( ); ③ if (success = = - 1 ) { ④ throw new TimedoutException( ) ⑤ } ⑥ }

    A.public void method( )

    B.public void method( ) throws Exception

    C.public void method( ) throw TimedoutException

    D.public throw TimedOutException void method( )


    正确答案:B
    解析:如果程序在运行的过程中抛出异常,而这个异常又不是Runtime-Exception或者Error,那么程序必须捕获这个异常进行处理或者声明抛出(throWs)该异常,捕获异常可以使用try{…}catch(){...}语句,而抛出异常在方法声明前是声明,在方法的声明后面加上throwsXxxxException,抛弃多个异常时,在各异常间使用逗号“,”分隔,题目中的程序在运行时抛出的不是一个RuntimeExeeption,所有必须捕获或者抛弃,而程序又没有捕获,所有应该在方法声明中声明抛弃。由于Exception是所有异常的父类,所有当然也可以代表RuntimeExccption了。

  • 第2题:

    给出下列的不完整的方法,则哪个声明可以被加入①行完成此方法的声明?( ) ① ② {success=connect(); ③ if(success==-1){ ④ throw new TimedOutException(); ⑤ } ⑥ }

    A.public void method()

    B.public void method()throws Exception

    C.public void method()throw TimedOutException

    D.public throw TimedOutException void method()


    正确答案:B

  • 第3题:

    下列关于throws关键字的描述中正确的是()

    A、thorws可以声明在方法上也可以声明在方法体中

    B、方法上使用throws抛出一个异常则这个方法中一定有trycatch代码块

    C、使用throws抛出多个异常时各个异常之间必须使用逗号隔开

    D、throws必须和throw配合使用


    正确答案:C

  • 第4题:

    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 end
    • B、 Compilation fails.
    • C、 test runtime end
    • D、 test exception end
    • E、 A Throwable is thrown by main at runtime.

    正确答案:D

  • 第5题:

    throw和throws的说法不正确的是()

    • A、throw是方法内抛出异常
    • B、throws是方法声明是抛出异常
    • C、throw可以抛出多个异常

    正确答案:C

  • 第6题:

    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、 finally
    • B、 exception finished
    • C、 finally exception finished
    • D、 Compilation fails.

    正确答案:C

  • 第7题:

    关于异常,下列的说法中不正确的是()。

    • A、用户可以根据需要抛出异常
    • B、在被调用方法可通过throw语句把异常传回给调用方法
    • C、用户可以自己定义异常
    • D、在C#中有的异常不能被捕获

    正确答案:D

  • 第8题:

    假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?() 

    • A、 raise ServiceException
    • B、 throw new ServiceException()
    • C、 throw ServiceException
    • D、 throws ServiceException

    正确答案:B

  • 第9题:

    单选题
    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

     finally

    B

     exception finished

    C

     finally exception finished

    D

     Compilation fails.


    正确答案: D
    解析: 暂无解析

  • 第10题:

    单选题
    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.


    正确答案: B
    解析: 暂无解析

  • 第11题:

    单选题
    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

     end

    B

     Compilation fails.

    C

     exception end

    D

     exception test end

    E

     A Throwable is thrown by main.

    F

     An Exception is thrown by main.


    正确答案: F
    解析: 暂无解析

  • 第12题:

    单选题
    现有:  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 middle

    B

     catch

    C

     late middle catch

    D

     catch Iate middle


    正确答案: C
    解析: 暂无解析

  • 第13题:

    54 、JAVA 语言如何进行异常处理,关键字:

    throws,throw,try,catch,finally 分别代表什么意义?在try 块

    中可以抛出异常吗?


    正确答案:

     

    Java 通过面向对象的方法进行异常处理,把各种不同的异常进行分类,并提供了良好的

    接口。在Java 中,每个异常都是一个对象,它是Throwable 类或其它子类的实例。当

    一个方法出现异常后便抛出一个异常对象,该对象中包含有异常信息,调用这个对象

    的方法可以捕获到这个异常并进行处理。Java 的异常处理是通过5 个关键词来实现的:

    try、catch、throw、throws 和finally。一般情况下是用try 来执行一段程序,如果出现

    异常,系统会抛出(throws)一个异常,这时候你可以通过它的类型来捕捉(catch)

    它,或最后(finally)由缺省处理器来处理。

    用try 来指定一块预防所有"异常"的程序。紧跟在try 程序后面,应包含一个catch 子句

    来指定你想要捕捉的"异常"的类型。

    throw 语句用来明确地抛出一个"异常"。

    throws 用来标明一个成员函数可能抛出的各种"异常"。

    Finally 为确保一段代码不管发生什么"异常"都被执行一段代码。

    可以在一个成员函数调用的外面写一个try 语句,在这个成员函数内部写另一个try 语句保

    护其他代码。每当遇到一个try 语句,"异常"的框架就放到堆栈上面,直到所有的try 语句都

    完成。如果下一级的try 语句没有对某种"异常"进行处理,堆栈就会展开,直到遇到有处理

    这种"异常"的try 语句。

  • 第14题:

    JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?


    正确答案:

     

    Java 通过面向对象的方法进行异常处理,把各种不同的异常进行分类,并提供了良好的接口。在Java中,每个异常都是一个对象,它是Throwable类或其它子类的实例。当一个方法出现异常后便抛出一个异常对象,该对象中包含有异常信息,调用这个对象的方法可以捕获到这个异常并进行处理。Java的异常处理是通过5个关键词来实现的:try、catch、throw、throws和finally。一般情况下是用try来执行一段程序,如果出现异常,系统会抛出(throws)一个异常,这时候你可以通过它的类型来捕捉(catch)它,或最后(finally)由缺省处理器来处理。
    用try来指定一块预防所有"异常"的程序。紧跟在try程序后面,应包含一个catch子句来指定你想要捕捉的"异常"的类型。
    throw语句用来明确地抛出一个"异常"。
    throws用来标明一个成员函数可能抛出的各种"异常"。
    Finally为确保一段代码不管发生什么"异常"都被执行一段代码。
    可以在一个成员函数调用的外面写一个try语句,在这个成员函数内部写另一个try语句保护其他代码。每当遇到一个try语句,"异常"的框架就放到堆栈上面,直到所有的try语句都完成。如果下一级的try语句没有对某种"异常"进行处理,堆栈就会展开,直到遇到有处理这种"异常"的try语句。

  • 第15题:

    下面的代码中方法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 Exception

    A.Ⅲ、Ⅳ

    B.Ⅱ、Ⅲ、Ⅳ

    C.Ⅰ、Ⅲ

    D.Ⅰ、Ⅳ


    正确答案:A
    解析:IOException异常类是Exception的子类。根据多态性的定义,IOException对象也可以被认为是Exception类型。还要注意,在方法声明中发出异常应用关键字throws。

  • 第16题:

    主动产生一个异常而非动态抛出的是()。

    • A、throw语句
    • B、throws语句
    • C、try…catch语句
    • D、finally语句

    正确答案:B

  • 第17题:

    关于异常,以下说法正确的有()。

    • A、运行时异常使用Runtime Exception的子类来表示,不用在可能抛出异常的方法声明上加throws子句
    • B、运行时异常使用Runtime Exception的子类来表示,必须在可能抛出异常的方法声明上加throws子句
    • C、非运行期异常是从Exception继承而来的,必须在方法声明上加throws子句
    • D、非运行期异常是从Exception继承而来的,不需要在方法声明上加throws子句

    正确答案:A,C

  • 第18题:

    关于异常,下列说法中不正确的是()

    • A、 用户可以根据需要抛出异常
    • B、 在调用方法中可通过throw语句把异常传回给调用方法
    • C、 用户可以自己定义异常
    • D、 在C#中有的异常不能被捕获

    正确答案:D

  • 第19题:

    现有:  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 middle
    • B、 catch
    • C、 late middle catch
    • D、 catch Iate middle

    正确答案:B

  • 第20题:

    多选题
    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?()
    A

    Class a will not compile.

    B

    Line 46 can throw the unchecked exception TestException.

    C

    Line 45 can throw the unchecked exception TestException.

    D

    Line 46 will compile if the enclosing method throws a TestException.

    E

    Line 46 will compile if enclosed in a try block, where TestException is caught.


    正确答案: A,C
    解析: 暂无解析

  • 第21题:

    单选题
    假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?()
    A

     raise ServiceException

    B

     throw new ServiceException()

    C

     throw ServiceException

    D

     throws ServiceException


    正确答案: D
    解析: 暂无解析

  • 第22题:

    单选题
    关于异常,下列的说法中不正确的是()。
    A

    用户可以根据需要抛出异常

    B

    在被调用方法可通过throw语句把异常传回给调用方法

    C

    用户可以自己定义异常

    D

    在C#中有的异常不能被捕获


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    关于异常,下列说法中不正确的是()
    A

     用户可以根据需要抛出异常

    B

     在调用方法中可通过throw语句把异常传回给调用方法

    C

     用户可以自己定义异常

    D

     在C#中有的异常不能被捕获


    正确答案: C
    解析: 暂无解析