try: except <never>:

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Tue Jan 10 07:53:21 EST 2006


I'd like an 'except <exception which is never raised>' statement
Is there a defined way to do that, for Python 2.2 and above?
'except None:' works for now, but I don't know if that's safe:

    for ex in ZeroDivisionError, None:
        try:
            1/0
        except ex:
            print "Ignored first exception."

I could just use
        except ZeroDivisionError:
            if not <first iteration>:
                raise
            print "Ignored first exception."
but the variant above gets a bit neater.

-- 
Hallvard



More information about the Python-list mailing list