aspose file tools*
The moose likes Beginning Java 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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception handling" Watch "Exception handling" New topic
Author

Exception handling

pratapsiva sivakumar
Greenhorn

Joined: Nov 10, 2008
Posts: 18
Hi sir,
I am using a try{ some code} and then finall{some code} block.I am not using catch block.So if an exception is thron in try block,how to handle it.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
pratapsiva sivakumar wrote:Hi sir,
I am using a try{ some code} and then finall{some code} block.I am not using catch block.So if an exception is thron in try block,how to handle it.


I believe the way you are doing it is the same as catch( Exception e ) {...}, except you don't get an exception object to work with. So youhave to make up your own message.
Filipe Pinheiro
Greenhorn

Joined: Oct 08, 2009
Posts: 9
You should either declare or manipulate it inside of the caller method
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Filipe Pinheiro wrote:You should either declare or manipulate it inside of the caller method
...


Hold on. If anything ever gets thrown in that situation, that means my answer that a finally is like a catch without the exception object to work with must be wrong.

Filipe, do you see any possible value in having a try without a catch?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Any checked exception must either be caught or declared to be thrown. So if you don't catch it, throw it on:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Thanks Rob for the example. I hadn't considered that there could be an exception other than that caused by a non-existent file.

I guess there might be a reason why you would want one or both exception types to be handled further up the stack, and still deal with closing the Reader within its scope. hence the try without a catch. Which means of course there is a reason for declaring the reader locally as opposed to passing the reader instead of the file name to this method.

regards.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception handling