• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception handling

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should either declare or manipulate it inside of the caller method
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any checked exception must either be caught or declared to be thrown. So if you don't catch it, throw it on:
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic