Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Ramesh Pramuditha Rathnayake
Ranch Hand

Joined: Oct 31, 2012
Posts: 169
    
    1



Why line 9 gives compile error while line 5 is being compiled..?
(This error occurs in JDK 1.7 only!)


Ramesh-X
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

The compiler reasons that the only type of Exception that you can catch in your catch-block is a runtime exception, which you may always rethrow without having to declare it.

Change the empty comment line to throw a non-runtime exception and you will see that the compiler will complain the same way for line 5.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception Handling