The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Exceptions

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Where to catch exceptions

Posted by Andre' Simmons on May 20, 1999 at 1:36 PM

> Bill Venners wrote:

> > My own thought is that one should catch exceptions in the
> > method that knows how to handle that exception, and that is
> > usually going to be at the application level. Exceptions let
> > you transfer control from the part of a program where an
> > error or problem is detected to another part of the program
> > that knows how to handle the error.

> This is good as far as it goes but I wonder about how locally
> you should catch exceptions. Suppose you have a method that
> makes several calls to an API, and each call can throw a couple
> of different exceptions. Do you put a little try-catch block
> around each call, or a big one around the whole method? Any
> style guidelines? Thanks.

In this case I believe it truly depends on the situation. If you are using an API that is independent of each call (i.e. one call has no bearing on the next call) then I would put all the calls under one try/catch. I am assuming that the problem is somehow related the the library itself not by recalling. If one call affects the previous call then I would stair-step the calls making sure to isolate the calls to better debug. Cascade exceptions could easily occur in this situation.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us