[FRPythoneers] trapping exceptions

Erick Bodine erick at allocity.com
Wed May 21 13:26:17 MDT 2003


Thanks Jim, I had a sneaking suspicion that I was trying to do too much.
Though, Mike Romberg's trick is pretty neat.  

--ERick


-----Original Message-----
From: Jim Vickroy [mailto:Jim.Vickroy at noaa.gov] 
Sent: Wednesday, May 21, 2003 11:33 AM
To: frpythoneers at lists.community.tummy.com
Subject: Re: [FRPythoneers] trapping exceptions


Erick,

As I see it, the problem is that in order for your "except" block to
work, a "MyException" must be raised.  If its your code raising the
exception, then you can obviously raise a "MyException" and it would
work as you intend.  But standard, distribution Python code raises
IOError exceptions which your except block does not handle.

In general, I do not see how you can do anything but the following:

def change_state(parm):
   pass

try:
    ...
except IOError, details:
    change_state(0)
else:
    ...

Erick Bodine wrote:

> All,
>
> I would like to create a custom exception class that would wrap 
> IOError so that I can catch its message string and do some other 
> things.  I made a stab at it with the below code, trying several 
> variations none of which were successful.  How is this accomplished 
> and is there a better way?
>
> class MyException(IOError):
>         def __init__(self):
>                 change_state(0)
>
> def change_state(value):
>         # change a value in a temp file
>
> try:
>         f = open('nonexistent.txt')
> except MyException, error:
>         print "IOError message"
>
> --ERick
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | 
> FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers

_______________________________________________
This message sent by the FRPythoneers mailing list.
Unsubscribe: echo unsubscribe |
FRPythoneers-request at lists.community.tummy.com
URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers



More information about the FRPythoneers mailing list