wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions ExamLab 6.0 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 "Exceptions ExamLab 6.0" Watch "Exceptions ExamLab 6.0" New topic
Author

Exceptions ExamLab 6.0

Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

ExamLab 6.0 does not allow user to save the test but I vaguely remember some question like this:



In such a case, why is there an compilation error at line 5 and not line 7. What is the logic used?


===Vyas Sanzgiri===
My Blog
Mohamamd Amin
Greenhorn

Joined: Jan 11, 2009
Posts: 7
The code within the try and catch statement does not throw InterruptedException. There will be no compilation errors when you remove the following statement:
catch (InterruptedException e) {
}

because catch(Exception e) will catch the exception and the program will terminate normally.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

InterruptedException is a subclass of Exception so why does the compiler "pick" on InterruptedException and not on Exception
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Vyas Sanzgiri wrote:InterruptedException is a subclass of Exception so why does the compiler "pick" on InterruptedException and not on Exception

Because the Java specification allows to catch Exception (but not specific checked exceptions.) The point is that you could catch a runtime exception with an Exception catch. And, the compiler can only enforce this rule for checked exceptions, because they are the only ones that methods are forced to declare.


All code in my posts, unless a source is explicitly mentioned, is my own.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

point noted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions ExamLab 6.0