How to catch 'error' type exceptions

Bengt Richter bokr at oz.net
Tue Jul 1 05:16:46 CEST 2003


On 30 Jun 2003 13:22:32 -0700, kevin at cazabon.com (Kevin Cazabon) wrote:

>Your problem is that "error" is not a valid exception type in Python. 
>You "should" be trying to catch a specific problem so that you can
>handle it appropriately (such as socket.error as mentioned by another
>poster).
>
>The lazy, dangerous way would be:
>
>try:
>    # some error-generating code
>except Exception, reason:
>    print reason
>
>but that's not recommended good coding practice.
>
Yes, certainly not internally, unless re-raising all or selected exceptions,
but as an outside wrapper to a whole app, why not? (You could make traceback
printing depend on __debug__ or some other option if desired).

You could also detect and eliminate redundant repetition in a traceback print
of a recursion limit exception. (I think that would be a nice default, BTW).

Regards,
Bengt Richter




More information about the Python-list mailing list