Conditional except: blocks

Robert Brewer fumanchu at
Fri Jan 2 18:38:09 CET 2004

I don't have a quesiton or problem, I just figured some of you would
enjoy the somewhat bizarre logic of the snippet I just wrote for a CGI
request dispatcher:

    return nextHandler(args)
except (None, Exception)[self.trapErrors], exc:
    if page == u'-Error':
        raise exc
        return self.handle_error(exc, scriptWithPath)

If self.trapErrors is True, all exceptions (which subclass Exception)
get trapped, otherwise, no exceptions are trapped. Spiffy. :)


More information about the Python-list mailing list