• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

join() always needs a try-catch block?

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Joe Lemmer
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
reply
    Bookmark Topic Watch Topic
  • New Topic