How to catch str exception?

Rhodri James rhodri at wildebst.demon.co.uk
Fri May 15 18:01:27 EDT 2009


On Fri, 15 May 2009 12:50:59 +0100, anuraguniyal at yahoo.com  
<anuraguniyal at yahoo.com> wrote:

>
>> try:
>>     raise "abc"
>> except:
>>     e, t, tb = sys.exc_info()
>>     if not isinstance(e, str):
>>         raise
>>     print "caught", e
>
> This seems to be the solution, thanks

Do be aware that string exceptions are going away, so at
some point you're going to upgrade your version of Python
and your scripts will mysteriously stop working.  Peter's
patch will help you for now, but it's a double-edged sword
in that it also lets you pretend that you don't have to
fix the problem properly later.  In my experience it's
generally best to fix the problem now rather than paper
over the cracks.

Since this is a third-party library doing this, as far as
I can see it you have three choices:

1) Get hold of a more up-to-date version of the module,
if there is one.

2) Ask the module writers nicely to fix the problem.

3) Fix it yourself.

The beauty of Python is that 3) isn't all that hard!

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list