aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes join() always needs a try-catch block? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "join() always needs a try-catch block?" Watch "join() always needs a try-catch block?" New topic
Author

join() always needs a try-catch block?

Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi there,

In K&B 6, ch 9, p.726 re: The join() method, we have example code:



Am I right in saying though that the Thread class's join() method always needs a try-catch block round it, because it can throw an InterruptedException? What I mean to say is I've checked in the API and it does, but I'm just wondering if I'm not getting something and there could be circumstances when you don't need a try-catch block.

Thanks

Joe


OCPJP 85%
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Joe Lemmer wrote:Hi there,

In K&B 6, ch 9, p.726 re: The join() method, we have example code:



Am I right in saying though that the Thread class's join() method always needs a try-catch block round it, because it can throw an InterruptedException?

Yes!
Joe Lemmer wrote:
What I mean to say is I've checked in the API and it does, but I'm just wondering if I'm not getting something and there could be circumstances when you don't need a try-catch block.

Thanks

Joe


There are chances to be interrupted the Thread, which in the blocked state. That's why, the join() method should be wrapped around try/catch block!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Thanks Abimaran.

I understand that there is a possibility of the Thread in the blocked state being interrupted. Thats good. I was just wondering why there was no try-catch block round the join() method in K&B. They don't make many mistakes and it was making me a bit nervous!

I am reassured now, though.

Cheers
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Because there focus at that time is to give you an idea about join method.
Moreover you can assume that , the method containing that part is ducking the Exception by mentioning throws InterruptedException

Cheers!!!

SCJP 6.0 96%

(Connecting the Dots ....)
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Joe Lemmer wrote:Thanks Abimaran.

I understand that there is a possibility of the Thread in the blocked state being interrupted. Thats good. I was just wondering why there was no try-catch block round the join() method in K&B. They don't make many mistakes and it was making me a bit nervous!

I am reassured now, though.

Cheers


Check the Errata! They may include it! Or else, check the API!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

Joe Lemmer wrote:I was just wondering why there was no try-catch block round the join() method in K&B.

The code is not complete, so you cannot surely say that there is not try-catch block around it. You can say that its not shown in the code...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: join() always needs a try-catch block?