Conditional except: blocks

Robert Brewer fumanchu at amor.org
Fri Jan 2 12:38:09 EST 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:

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

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


FuManChu




More information about the Python-list mailing list