Error
Michael Hudson
mwh21 at cam.ac.uk
Wed May 24 15:47:04 EDT 2000
Thomas Thiele <thiele at muc.das-werk.de> writes:
> I have some code with a try and except
>
> try:
>
> function_that_rises_many_types_of_exceptions()
> except:
> print "error, but I don't know what was happend!"
>
>
> I use except without any argument to catch all kind of exceptions.
> But how can I get the type of exception without having to write down all
> exceptions?
>
> Is there function like GetLastException() ?
In the except: block, look at sys.exc_info():
>>> try:
... raise RuntimeError, "hiya!"
... except:
... print sys.exc_info()
...
(<class exceptions.RuntimeError at 80b3b88>,
<exceptions.RuntimeError instance at 8129950>,
<traceback object at 80ce3e0>)
After the except: block has finished, you might want to look at
sys.last_*, but I think you want the sys.exc_* ones...
HTH,
Michael
--
After a heavy night, I travelled on, my face toward home - the comma
being by no means guaranteed. -- paraphrased from cam.misc
More information about the Python-list
mailing list