Exceptions

Emile van Sebille emile at fenx.com
Thu May 30 02:54:15 EDT 2002


destr0
> I'm having trouble with exceptions.  I'm writing a program where I
want to
> catch an exception and extra data and use that data to send an email.
>
> def func1():
>     raise queryError, "There was an Error"
> #first of all.. .am I giving the exception name properly?
>
> try:
>     func1()
> except:
>     #I'm having trouble putting together a statement here to     #grab
the
> extra data I sent to use for something else.
>
> do I use:
> except queryError, data:
>     print data
>
> When I do this I get mixed results.. sometimes it seems to throw an
extra
> name exception for queryError.  Also.. I don't like this.. because I'd
like
> to be able to catch all exceptions and latch on to their data, instead
of
> explicitly writing a catch statement for each exception I might have .
>
>

Assuming you have something like this preceding the above:

import sys
class queryError(Exception):pass

you could use:

try: func1()
except Exception, data:
    print 'the data is:',data
    print 'other info:', sys.exc_info()

HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list