Catching Exceptions.

Phil Frost indigo at bitglue.com
Mon Sep 27 14:11:21 EDT 2004


As mentioned by others, it is advisable in most cases to catch specific
exceptions. However there are times when catching *all* exceptions is
desirable. In these cases it's also pretty important that even string
exceptions or classes that do not inherit from Exception are caught. For
example, in a web server, any exception should terminate the request
with error, not destroy the server process.

In these cases, sys.exc_info() provides the missing information. Also
you may find the traceback module to be of use.

On Mon, Sep 27, 2004 at 08:44:52AM -0700, Keith Bolton wrote:
> I am handling exceptions currently using try, except.  Generally I don't
> handle specific exceptions and am catching all.
> Then if an exception occurs, I would like to capture that error string.
>  However, in the documentation it seems like 
> there is not a way to get the extra str data if you are handling all
> exceptions and not specifically.  Is there?
> 
> thanks
> 
> -keith



More information about the Python-list mailing list