• 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 chaining and handling

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I have never make in a practice the exception handling and i have no any experience with it. I have some questions about exception chaining and handling could you help me?



In this example I catch Exception1 and rethrow the Exception2. Since JDK 1.4 there is a possibility to add to the Exception2 a cause of the Exception1. But If I didn't throw the cause of the Exception1 is this also an exception chaining? Or the meaning of chaining is only if the cause (Throwable) of one exception will be thrown with the cause of another.

Another example. How is a best way to rethrow an exception in practice?

or



If I have e.g. three calls of different methods that catch one exception and rethrow the another one. Do I need to rethrow the cause of these exceptions every time and log at the end point all exceptions :

or just log the occurred exception before throwing and throw only the message?
How it will be made in a real applications?
Thanks a lot for your help!
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well what you're talking about is checked & unchecked exceptions.

unchecked exceptions should extend RuntimeException (they flow all the way up to the top of the stack unless you specifically catch it and do something w/ it) this is what the springframework uses.


checked exceptions are caught and handled with.

it is always preferred to do catch them and keep the original message

}catch(Exception e){
throw new BusinessLogicException(e);
}

... safe rule of thumb is to have business logic exceptions checked, and handled for whatever reason or however.. and system problems (sql, dataccess, etc unchecked).

hope that helps


www.binaryfrost.com
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic