aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock Exam question, Interrupted Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock Exam question, Interrupted Exception" Watch "Mock Exam question, Interrupted Exception" New topic
Author

Mock Exam question, Interrupted Exception

Klemens Katterbauer
Greenhorn

Joined: Jul 15, 2008
Posts: 8
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 ]

Klemens Katterbauer<br />Student of Mathematics,<br />University of Vienna
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
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

Joined: Jul 15, 2008
Posts: 8
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?
Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
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.


Studying for SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Exam question, Interrupted Exception