[FRPythoneers] trapping exceptions
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.
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
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:
except IOError, details:
Erick Bodine wrote:
> 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):
> def change_state(value):
> # change a value in a temp file
> f = open('nonexistent.txt')
> except MyException, error:
> print "IOError message"
> 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
More information about the FRPythoneers