This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
hi, i dont understand about the throws modifier. for example, why do i have to throw java.lang.InterruptedException if i want to use thread in the method body?, why cant i use try and catch statement before i use thread in my code and try to catch the exception instead? can a method throw more than one exception? thanks
----------------------------------<br />SCJP 1.4
karl koch
Ranch Hand
Joined: May 25, 2001
Posts: 388
posted
0
hi
yes, a method can throw more than one Exceptions:
you dont need to declare the Exception if you catch it:
if you use
then you catch all subclasses of Exception.
k
J.H.B. Oosterlaar
Ranch Hand
Joined: Sep 12, 2002
Posts: 41
posted
0
Originally posted by Syamsul Hussin: hi, i dont understand about the throws modifier. for example, why do i have to throw java.lang.InterruptedException if i want to use thread in the method body?, why cant i use try and catch statement before i use thread in my code and try to catch the exception instead?
You don't have to throw the InterruptedException, you can simply catch it within the method. I don't know what makes you believe otherwise. For example:
Jeroen Oosterlaar
Syamsul Hussin
Ranch Hand
Joined: Feb 09, 2003
Posts: 59
posted
0
Hi, if I declare a class to extend a super which throws an exception, do I have to throw the same exception again? thanks