Error

Shae Erisson shapr at uab.edu
Wed May 24 18:56:09 EDT 2000


Thomas Thiele wrote:
> 
> 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() ?

is this what you're asking for?:

try:
    f = open('/tmp/blah.txt')
except IOError, e:
    print "SPAM!",e

this will let you catch _just_ an IOError (like no, such file or dir)
but you can also replace the except line with:

except (IOError, AssertionError),e:

if you want to catch multiple types of exceptions on this line.
-- 
sHae mAtijs eRisson (sHae at wEbwitchEs.coM) gEnius fOr hIre
   bRing mE fIve sQuirrels aNd nO oNe wIll gEt hUrt
13:00pm up 1 season, 1 squirrel, load average: 1+1j 0.5+2j 0.2+0.5j



More information about the Python-list mailing list