This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Mock Exam question, Interrupted Exception

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody know why an Interrupted Exception is thrown here.

The only explanation I have is that due to the two distinct run methods and the InnerRunTwo's thread relationship to InnerRun, follows that when I invoke the first Thread t, it will disrupt the Thread 'u', but I'm not sure.




Thanks for comments.
[ July 27, 2008: Message edited by: Klemens Katterbauer ]
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception cannot be thrown in this code.
This code simply doesn't compile, because according to Thread.join() api, join() throws the checked InterruptedException that must be catch in your code or must be declared to be thrown by run() method.
Surround other.join() statement with try-catch, like this:

and it will compile.

regards
[ July 27, 2008: Message edited by: Ireneusz Kordal ]
 
Klemens Katterbauer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that but why do I have to surround the other.join by a try and catch block or have to throw an exception ?

That's my questions?
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java requires that if a method throws an exception, you must either include it in a try/catch block, or declare that your method that's calling the "unsafe" method throws that exception. It's part of java's syntax.
 
What's gotten into you? Could it be this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic