| Author |
Exceptions
|
Vineela Devi
Ranch Hand
Joined: Dec 20, 2003
Posts: 191
|
|
Hi, Is the hierachy significant in throws statement.i.e.is it illeagl to declare a method as void method() throws Exception, IOException{ throw new IOException(); } ofcourse i know tht there is no need to throw IOException in the above method . but i just want to know whether hierachy is significant in throws statement. Thanks in advance. vineela
|
 |
Vicken Karaoghlanian
Ranch Hand
Joined: Jul 21, 2003
Posts: 522
|
|
If there is a throws clause in the signature of a method, then that method can actually throw one of those: No exceptions at all. The same exception that is declared in the method signature. Any exception that is a subset of the exception declared in the method's signature.
|
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
|
 |
Vineela Devi
Ranch Hand
Joined: Dec 20, 2003
Posts: 191
|
|
hi Vicken, Thanks for the reply.I know the points u have specified. i wanted to know whether the code posted by me is illegal coz in some Certification book, it is mentioned tht the hierachy is significant in throws clause. vineela
|
 |
Sudhakar Krishnamurthy
Ranch Hand
Joined: Jun 02, 2003
Posts: 76
|
|
|
Nope, their is no hierarchy that you need to follow, your code should compile fine. But i hope you understand you would never have to do that since the base class exception is going to take precedence over the subclass exceptions when it is caught.
|
 |
Thomas De Vos
stable boy
Ranch Hand
Joined: Apr 12, 2003
Posts: 425
|
|
|
Additionally on the three bullet points mentioned in the posting from Vicken. The method can throw also unchecked exceptions like: NullPointerException, RuntimeException, etc.
|
Try your free <a href="http://www.javacertificate.com" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="http://www.j2eecertificate.com" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="http://www.ejbcertificate.com" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="http://www.webspherecertificate.com" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="http://www.j2mecertificate.com" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="http://blogs.javacertificate.com" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>
|
 |
 |
|
|
subject: Exceptions
|
|
|