Which exceptions are recommended to me handled?

Fredrik Lundh fredrik at pythonware.com
Mon Jun 5 06:53:39 EDT 2006


Delaney, Timothy (Tim) wrote:

> Note that it's a particularly bad idea to just replace one exception
> with another exception (not suggesting that that is what you intended -
> just something I've seen a lot ;)
> 
>     try:
>         int(val)
>     except ValueError:
>         raise MyValueError('Bad value: ' + val)
> 
> 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.

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

</F>




More information about the Python-list mailing list