当前位置: 技术问答>java相关
关于throw和throws方法的区别?
来源: 互联网 发布时间:2015-03-10
本文导语: 这题大家选什么? How will you declare mymethod so that it will throw a Exception? Select one? A. In method declaration give throw Exception and inside the method give throws Exception B. In method declaration give throws Exception and inside th...
这题大家选什么?
How will you declare mymethod so that it will throw a Exception? Select
one?
A. In method declaration give throw Exception and inside the method
give throws Exception
B. In method declaration give throws Exception and inside the method
give throw Exception
C. In method declaration give throw Exception and inside the method
give throw Exception
D. In method declaration give throws Exception and inside the method
give throws Exception
请大家帮忙分析一下
How will you declare mymethod so that it will throw a Exception? Select
one?
A. In method declaration give throw Exception and inside the method
give throws Exception
B. In method declaration give throws Exception and inside the method
give throw Exception
C. In method declaration give throw Exception and inside the method
give throw Exception
D. In method declaration give throws Exception and inside the method
give throws Exception
请大家帮忙分析一下
|
A throws clause is used to declare any checked exceptions that can result from the execution of a method or constructor.
A throw statement causes an exception to be thrown. The result is an immediate transfer of control that may exit multiple statements and multiple constructor, static and field initializer evaluations, and method invocations until a try statement is found that catches the thrown value. If no such try statement is found, then execution of the thread that executed the throw is terminated after invocation of the UncaughtException method for the thread group to which the thread belongs.
A throw statement causes an exception to be thrown. The result is an immediate transfer of control that may exit multiple statements and multiple constructor, static and field initializer evaluations, and method invocations until a try statement is found that catches the thrown value. If no such try statement is found, then execution of the thread that executed the throw is terminated after invocation of the UncaughtException method for the thread group to which the thread belongs.
|
B
throw语句用在方法体内,表示抛出异常,由方法体内的语句处理
throws语句用在方法声明后面,表示再抛出异常,由调用这个方法的上一级方法中的语句来处理
throw语句用在方法体内,表示抛出异常,由方法体内的语句处理
throws语句用在方法声明后面,表示再抛出异常,由调用这个方法的上一级方法中的语句来处理
|
B
|
B. In method declaration give throws Exception and inside the method
give throw Exception
|
B
|
非B,我掉牙。