Thursday, July 23, 2009

Exception Handling - Code for failures - Part-2

Part-1 is here...
Part-3 is here...
Exception can be thrown for two reasons
1. Application failure, which includes operational failures, code issues and all other technical issues. (mostly non recoverable by end user)

2. Business validations. (mostly recoverable by end user by changing the input data)


If any failure happened,
we required below information to fix the issue

1. What was the failure?
2. Where it happened?
3. Which circumstance or state or environment?
4. What are the input data?
5. Is this recoverable?
6. Is it necessary to Alert / Escalate to the support people?


Our Exception handling must provide all these details whenever the failure happened.

How do we provide these information?

1. What was the failure?
Do not throw a generic high level exception, provide a more specific Exception class.

2. Where it happened?
Do not throw a generic high level exception, provide a more specific Exception class, if we use the Same exception class in many places differentiates with the Id or message. so we know exactly where the failure happened.

3. Which circumstance or state or environment?
This is very important, many time we programmers do not mind that our program work only in a Conditional state(or environment), so we need to provide this information while throwing exception by id orMessage.

The exception handler (typically a catch block or caller method) would change the state or look foralternate and re-try before throw the exception.

4. What are the input data?
This information is important for Exception handling, most of the time exception could happened by theinput data, throw proper data exception when the failure happened like NullArgumentException

5. Is this recoverable?
Most of the time, we throw Validation Exceptions, these validation exceptions would be recoverable by the end user, so the handling code must know that these exceptions are recoverable exceptions, so we Provide more meaningful information to recover this to the end user.

Secondly this would use to hold the same state or environment for the end user to continue working with the application.

6. Is it necessary to Alert / Escalate to the support people?
Not all the exceptions required admin or support people to be informed, so providing this information to the handler code will alert the admin or support team accordingly.

If we get all the mentioned information without seeing the log, code and trace is consider the better Exception handling.

The Exception handling tips Will be continued…

10 comments:

Anonymous said...

Approvingly your article helped me truly much in my college assignment. Hats off to you send, wish look progressive for the duration of more interrelated articles without delay as its united of my choice question to read.

javaPuru said...

Hi, The 3rd part in this exception handling also written already please find the link here http://www.javapuru.com/2009/11/exception-handling-do-and-donts-code.html

Anonymous said...

Thanks for an idea, you sparked at thought from a angle I hadn’t given thoguht to yet. Now lets see if I can do something with it.

netbeans said...

this finishes the reading on exception handling, thanks a lot

louis vuitton outlet said...

Tory Burch Outlet
Michael Kors Outlet Ralph Lauren Outlet Gucci Factory Outlet Gucci Outlet Gucci Handbags Cheap Ray Ban Sunglasses North Face Jackets Prada Outlet Burberry Outlet Hollister Clothing Ferragamo Shoes Tiffany Jewelry Tiffany Outlet NFL Jerseys Cheap Jordans Oakley Outlet North Face Outlet Burberry Outlet Ray Ban Sunglasses
Chan Luu Sale Toms Outlet Burberry Outlet Oakley Sunglasses Toms Shoes Sale Beats By Dr Dre Coach Outlet Christian Louboutin Shoes Oakley Sunglasses Valentino Shoes
Oakley Eyeglasses Michael Kors Outlet Coach Factory Outlet Coach Outlet Online Coach Purses Kate Spade Outlet Toms Shoes North Face Outlet Coach Outlet Gucci Belt

Cran Kate said...

Burberry Belt Tory Burch Boots Louis Vuitton Belt Ferragamo Belt Marc Jacobs Handbags Lululemon Outlet Christian Louboutin Shoes True Religion Outlet Tommy Hilfiger Outlet
Michael Kors Outlet Coach Outlet Red Bottoms Kevin Durant Shoes New Balance Outlet Adidas Outlet Coach Outlet Online Stephen Curry Jersey Vans Outlet Ralph Lauren Outlet
Ugg Boots Sale UGGS For Women Skechers Go Walk Adidas Yeezy Boost Adidas Yeezy Adidas NMD Coach Outlet North Face Outlet Ralph Lauren Outlet Puma Outlet Polo Outlet
Under Armour Outlet Under Armour Hoodies Herve Leger MCM Belt Nike Air Max Louboutin Heels Jordan Retro 11 Converse Outlet Nike Roshe Run UGGS Outlet North Face Outlet

chenzhen said...

valentino
red bottoms outlet online
birkenstock shoes
oakley sunglasses cheap
gucci borse
skechers outlet
versace sunglasses
louis vuitton handbags
jimmy choo outlet store
michael kors bags
kate spade outlet online
hollister clothing store
designer handbags wholesale
nike shoes for cheap
adidas pure boost black
reebok classic
michael kors outlet
oakley sunglasses outlet
michael kors outlet online
coach factory outlet
true religion uk
coach outlet online
tiffany uk
jimmy choo
north face outlet
dolce and gabbana outlet online
nike running shoes
ecco outlet
cheap ray ban sunglasses
coach outlet store
under armour
oakley sunglasses outlet
nike air max 90
louis vuitton uk
chi flat iron
cheap ray bans
pandora jewelry
pandora charms uk
michael kors outlet clearance
burberry outlet canada
chenzhen2016629

Meiqing Xu said...

valentino
adidas nmd
beats by dr dre
yeezy boost
michael kors outlet
lebron james shoes 2017
true religion outlet
philadelphia phillies jerseys
mbt shoes
kate spade handbags
20170322caiyan

Unknown said...

RBSE Result 2017
Karnataka 2nd PUC Result 2017
PSEB Result 2017
Maharashtra SSC Board Result 2017

Nilesh sharma said...

Kerala DHSE +2 Result 2017
MP Board 12th Result 2017
Maharashtra Board HSC Result 2017
UP 12th Class Result 2017
Odisha CHSE Result 2017