Which exceptions are recommended to me handled?

Delaney, Timothy (Tim) tdelaney at avaya.com
Mon Jun 5 17:29:28 EDT 2006


Fredrik Lundh wrote:

> Delaney, Timothy (Tim) wrote:
> 
>> The most important problem here is that you've lost the stack trace
from
>> the original exception.
>
> which, in many cases, is a good thing, especially if you replace "int"
> with a call to some low-level support library.  if I call API "foo" to
> open a data file of some kind, I'm not necessarily interested in an
> "unsubscriptable error" exception on line 129 in barpath.py, nor is it
> helping me figure out what's wrong in my program.

I always prefer to have the stack trace, since it *is* useful to me to
figure out what is wrong with my program (or possibly, the library I'm
using).

> or do you expose internal implementation details to your end users
> too, to make sure they don't lose any information?

No - but I do log any errors, with stack traces, and as much useful data
as possible. That way it's more likely that I can get a useful bug
report (they send the log file).

Replacing an exception *may* not get in the way if you're wrapping a
single statement in the exception. I can't think of another case where
it would not get in the way. Chained exceptions change this somewhat,
because you don't lose the original information.

Tim Delaney



More information about the Python-list mailing list