Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Exception handling patterns/techniques

Thread view: 
James L - 05 Mar 2008 10:57 GMT
How do you all feel about the commonly-seen technique of exception
wrapping? It can keep interfaces clean - but then you end up breaking
compile-time exception handling checking, as pointed out here:

http://weblogs.java.net/blog/bakksjo/archive/2005/09/java_exception.html

(and you risk never dealing with exceptions that are added to the code
later on...)

Also, suppose I have a class that contains ten methods, each of which do
something similar (e.g. comms) which can throw the same five exceptions
each time. Is there a handy pattern for refactoring those five catch
statements into one place, if such a thing were desirable?[1] (This is
maybe drifting into the area of aspect-oriented programming...)

One naive way might be to have each of the ten methods call a single
method with parameters, which contains a switch which calls the correct
ultimate target method - then you just have one try...catch wrapping
that switch statement. This is pretty ugly though.

[1] I realise that such a thing might very rarely be actually desirable!

thanks,
J
Mark Space - 05 Mar 2008 16:43 GMT
> How do you all feel about the commonly-seen technique of exception
> wrapping? It can keep interfaces clean - but then you end up breaking
> compile-time exception handling checking, as pointed out here:

I've heard a rumor that Java 7 will contain some sort of official
support for wrapping exceptions.  I'm kinda bummed about that, since I
don't think it will encourage clean code to be written, but I guess
market pressure is pushing Sun into it.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.