def catches(exc, handler=re_raise):
    '''
    Function decorator. Used to decorate function that handles exception class exc.

    An optional exception handler can be passed as a second argument. This exception
    handler shall have the signature
            handler(exc, message, traceback).
    '''
    if not __CHECKING__:
        return lambda f: f

    def wrap(f):
        def call(*args, **kwd):
            try:
                ID = exc_checker.set_attention(exc)
                res = f(*args, **kwd)
                exc_checker.remove_attention(exc, ID)
                return res
            # handle checked exception
            except exc, e:
                exc_checker.remove_attention(exc, ID)
                traceback = sys.exc_info()[2]
                return handler(exc, str(e), traceback.tb_next.tb_next)
            # re-raise unchecked exception but remove checked exeption info first
            except Exception, e:
                exc_checker.remove_attention(exc, ID)
                traceback = sys.exc_info()[2]
                raise e.__class__, e.args, traceback.tb_next.tb_next
        call.__name__ = f.__name__
        return call
    return wrap
def catches ( exc , handler = re_raise ) : if not __CHECKING__ : return lambda f : f def wrap ( f ) : def call ( * args , ** kwd ) : try : ID = exc_checker . set_attention ( exc ) res = f ( * args , ** kwd ) exc_checker . remove_attention ( exc , ID ) return res except exc , e : exc_checker . remove_attention ( exc , ID ) traceback = sys . exc_info ( ) [ 2 ] return handler ( exc , str ( e ) , traceback . tb_next . tb_next ) except Exception , e : exc_checker . remove_attention ( exc , ID ) traceback = sys . exc_info ( ) [ 2 ] raise e . __class__ , e . args , traceback . tb_next . tb_next call . __name__ = f . __name__ return call return wrap
Function decorator. Used to decorate function that handles exception class exc.

    An optional exception handler can be passed as a second argument. This exception
    handler shall have the signature
            handler(exc, message, traceback).