This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Exception Handling" Watch "Doubt in Exception Handling" New topic
Author

Doubt in Exception Handling

ayush raj
Ranch Hand

Joined: Jan 15, 2012
Posts: 60
What should be the output ?


I thought it to be Runtime exception since a number is divided by zero . But actually compilation fails !! How?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4246
    
    7

And compilation fails with what error message?
ayush raj
Ranch Hand

Joined: Jan 15, 2012
Posts: 60
the error message is :

exception java.lang.InterruptedException is never thrown in body of corresponding try statement

Is it that that what ever exception is thrown inside a try block , the first catch has to be the corresponding class exception handler ??

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4246
    
    7

That's the problem. InterruptedException is a checked exception. The compiler therefore knows that it cannot possibly be thrown from the try block, so it knows that trying to catch it is an error. Runtime exceptions don't have the same effect (even though in this case theoretically the compiler could work out that ArrayIndexOutOfBoundsException can't be thrown).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Exception Handling
 
Similar Threads
catching general exceptions before
Exceptions (Khalid & Rolf 's book)
Q of Dan's Mock Exam
throws Exception
Is there any mistake in this Thread code.