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 / October 2006

Tip: Looking for answers? Try searching our database.

exception handling patterns?

Thread view: 
Timasmith - 17 Oct 2006 13:14 GMT
Hi,

Does anyone know of some good articles on exception handling.  From my
own experience this is where I am at:

System (as in the application) defined exceptions should

  a) Extend something like a system.lang.xxxException when you want to
defend but you dont want to force the method user to catch/throw the
exception
  e.g. NullArgumentException extends NullPointerException

  b) Extend Exception when you need the method user to handle the
specific exception
  e.g. InvalidUserNameException extends Exception

  c) Extend your own exceptions when you have a commonality that the
user could protect against
  e.g. SQLException extends DataAccessException
  e.g. DataParameterException extends DataAccessException

Not sure what else to do around Exception Handling other than handle
them gracefully.
Oliver Wong - 17 Oct 2006 15:17 GMT
> Hi,
>
[quoted text clipped - 11 lines]
> specific exception
>   e.g. InvalidUserNameException extends Exception

   Your rule "A" should be changed so that the exceptions of interest
extend RuntimeException, or one of its subclasses. NullPointerException is a
subclass of RuntimeException, so the example still works.

   Similarly, in "B" you could extend any exception which is not a
RuntimeException (Exception itself is an exception, but not a runtime
exception).

   Also, don't be afraid to occasionally throw one of Sun's built-in
exceptions, instead of defining your own.

   - Oliver


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.