
Part-1 is here...
Part-2 is here...
Do's and Don'ts in Exception Handling
1. Do not suppress the exception
2. Do catch the specific exception than the toplevel or generic exceptions
3. Do handle the thrown exception.
4. Do not throw the irrelevant exceptions to the caller
5. Do not handle the irrelevant exception by own.
6. Do Wrap-up the exception
1. Do not suppress the exception
try{
// File reading code here
}catch(IOException ioEx){
// do Nothing
}
Often we use try catch block in our code when compiler/IDE force as to handle the checked exceptions, we do write try catch block and just leave the catch block as
Empty, first of all we must handle these checked exceptions, that's the reason it has been forced by compilers, by leaving empty catch block, we defeat the purpose of these checked exceptions.
2. Do catch the specific exception than the top-level or generic exceptions
Catch the specific exceptions as much as possible; do not just catch the generic exceptions.
try{
// File reading code here
}catch(FileNotFoundException fnfEx){
// do something
}catch(IOException ioEx){
// do something
}catch(Exception ex){
// do something
}
3. Do handle the thrown exception.
Compiler won't force us to handle the unchecked exceptions, it doesn't mean we no need to handle, for the good exceptiona handling must handle all the exceptions as much as possible.
4. Do not throw the irrelevant / unknown exceptions to the caller
This is one of the important point in exception handling, code shouldn't throw all the exceptions to the caller, if any exception which can be handled by own, that exceptions must be handled then and there, for example, a method is trying to connect to Database and it throws Connection Could not established exception, then code should not throw this to handler, the method must handle and do some recoveries like re try or try to connect to the alternate Database. the caller may not know what to do with this exception, so this must be handled then and there.
5. Do not handle the irrelevant exception by own.
Like the above point, the code must not handle the exceptions which are not relevant to that piece, it should throw the exception to the caller.
6. Do Wrap-up the exception
From the bottom to top, if the code throws all the exceptions as it is, the top level must handle or know about too many exceptions, so must wrapper the exceptions, log down it and pass to the above layer.
For example, if DAO layer got some exception like SQLExcpetion, the end user or UI not necessarily say what is the error, instead this code wrap up as SystemException and pass it to the above layer, even though wrap that to system exception it should be logged down properly in the log files as SQLException, otherwise developer or operation people get confused about the exceptions.
2. Do catch the specific exception than the toplevel or generic exceptions
3. Do handle the thrown exception.
4. Do not throw the irrelevant exceptions to the caller
5. Do not handle the irrelevant exception by own.
6. Do Wrap-up the exception
1. Do not suppress the exception
try{
// File reading code here
}catch(IOException ioEx){
// do Nothing
}
Often we use try catch block in our code when compiler/IDE force as to handle the checked exceptions, we do write try catch block and just leave the catch block as
Empty, first of all we must handle these checked exceptions, that's the reason it has been forced by compilers, by leaving empty catch block, we defeat the purpose of these checked exceptions.
2. Do catch the specific exception than the top-level or generic exceptions
Catch the specific exceptions as much as possible; do not just catch the generic exceptions.
try{
// File reading code here
}catch(FileNotFoundException fnfEx){
// do something
}catch(IOException ioEx){
// do something
}catch(Exception ex){
// do something
}
3. Do handle the thrown exception.
Compiler won't force us to handle the unchecked exceptions, it doesn't mean we no need to handle, for the good exceptiona handling must handle all the exceptions as much as possible.
4. Do not throw the irrelevant / unknown exceptions to the caller
This is one of the important point in exception handling, code shouldn't throw all the exceptions to the caller, if any exception which can be handled by own, that exceptions must be handled then and there, for example, a method is trying to connect to Database and it throws Connection Could not established exception, then code should not throw this to handler, the method must handle and do some recoveries like re try or try to connect to the alternate Database. the caller may not know what to do with this exception, so this must be handled then and there.
5. Do not handle the irrelevant exception by own.
Like the above point, the code must not handle the exceptions which are not relevant to that piece, it should throw the exception to the caller.
6. Do Wrap-up the exception
From the bottom to top, if the code throws all the exceptions as it is, the top level must handle or know about too many exceptions, so must wrapper the exceptions, log down it and pass to the above layer.
For example, if DAO layer got some exception like SQLExcpetion, the end user or UI not necessarily say what is the error, instead this code wrap up as SystemException and pass it to the above layer, even though wrap that to system exception it should be logged down properly in the log files as SQLException, otherwise developer or operation people get confused about the exceptions.
11 comments:
Keep posting stuff like this i really like it
Genial brief and this mail helped me alot in my college assignement. Say thank you you for your information.
femdom the mature enchantress
sexy naked pictures of brunettes
plaid strip
brunette vidieo
bacillus subtilis spore strip msds
[URL=http://madsextapes.servik.com/index.html]fucking whore[/URL]
[URL=http://madsextapes.servik.com/sitemap.html]get fucking whore[/URL]
[URL=http://madsextapes.servik.com/malaysian-nudes.html]malaysian nudes[/URL]
[URL=http://madsextapes.servik.com/expert-chicks.html]expert chicks[/URL]
[URL=http://madsextapes.servik.com/german-pornstars-video-download.html]german pornstars video download[/URL]
[URL=http://madsextapes.servik.com/cuckold-whores.html]cuckold whores[/URL]
[URL=http://madsextapes.servik.com/celebrity-facial.html]celebrity facial[/URL]
[URL=http://madsextapes.servik.com/woman-nude-models.html]woman nude models[/URL]
[URL=http://madsextapes.servik.com/cumming-clit-2010-jelsoft-enterprises-ltd.html]cumming clit 2010 jelsoft enterprises ltd[/URL]
[URL=http://madsextapes.servik.com/girls-clits.html]girls clits[/URL]
[URL=http://madsextapes.servik.com/desperate-teens.html]desperate teens[/URL]
[URL=http://madsextapes.servik.com/blonde-pic-flix-of-herself.html]blonde pic-flix of herself[/URL]
http://fujser.cz.cc/9056H.html Phim sex tinh cam
http://ulides.cz.cc/2549A.html Best of intercourse video files
http://dsuia.cz.cc/q3707H.html Main dengan ibu tiri
http://odlesa.tk/o8771.html Cerita kisah sex anak anak kecil melayu
http://hkeeyt.tk/?p=3994 Precious moments christmas nativity scene coloring pages
http://fteeres.cz.cc/b0598K.html Schematic diagram of asbestosis
http://xeniua.tk/?p=8638 Nude picture of beutiful young kadazan girls
http://sfaiw.tk/?p=6450 Co em nao muon dit ko
http://nugio.cz.cc/4057L.html Cerita ina dientot
http://sfaiw.tk/?p=1850 Trang phim nguoi lon hay nhat viet nam
http://fteeres.cz.cc/g7229J.html Fesyen gaun dan tudung
http://nugio.cz.cc/2289F.html Plugin dvd windows
http://dsuia.cz.cc/r7992Q.html Phim hai chi em sec
http://dsewq.cz.cc/5406P.html Cai nhac cho dien thoai
http://biosaki.cz.cc/v9084K.html Tied gagged tickled girls
http://wikiinfo.tk/What-Is-A-Metasearch-Engine.html What is a metasearch engine
http://nugio.cz.cc/0665O.html Kontol putih cowo
http://nugio.cz.cc/6165V.html Zelda on visual gba
http://fujser.cz.cc/0896K.html Cerita seks anak sd dan mama ngentot
http://nugio.cz.cc/1117Y.html Funny macros in wow
[/url]
[/url]
[/url]
[url=http://bestreviewsonline.net/employee-satisfaction-surveys-guide/#comment-31811]cerita pantat busuk
[/url]
[/url]
You are presented with flowers?
DELETE THIS TOPIC!!
[url=http://thesmogallert.in.com]Look at this[/url]
You are presented with flowers?
Sorry admin - my post is test
Amazon launched two new Kindle e-readers priced at $139 and $189 late Wednesday, with the cheaper version a Wi-Fi-only e-reader and $10 less than the Wi-Fi-only Nook.
[url=http://www.computerworld.com/s/article/9179853/Amazon_launches_two_new_Kindles_one_with_Wi_Fi_only]ComputerWorld[/url]
http://www.computerworld.com/
[URL="http://nysf.com/nysc/what-is-cialis-and-generic-cialis.html"]What is cialis and generic cialis[/URL]
Post a Comment