#NEWLINE# def wrap_exception( notifier = None , get_notifier = None ) : #NEWLINE# #INDENT# 'This decorator wraps a method to catch any exceptions that may\n    get thrown. It also optionally sends the exception to the notification\n    system.\n    ' #NEWLINE# def inner( f ) : #NEWLINE# #INDENT# def wrapped( self , context , * args , **kw ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return f ( self , context , * args , ** kw ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) : #NEWLINE# #INDENT# if ( notifier or get_notifier ) : #NEWLINE# #INDENT# payload = dict ( exception = e ) #NEWLINE# wrapped_func = safe_utils . get_wrapped_function ( f ) #NEWLINE# call_dict = inspect . getcallargs ( wrapped_func , self , context , * args , ** kw ) #NEWLINE# call_dict . pop ( 'self' , None ) #NEWLINE# cleansed = _cleanse_dict ( call_dict ) #NEWLINE# payload . update ( { #NEWLINE# #INDENT# 'args' : cleansed , #NEWLINE# #UNINDENT# } ) #NEWLINE# event_type = f . __name__ #NEWLINE# ( notifier or get_notifier ( ) ) . error ( context , event_type , payload ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return functools . wraps ( f ) ( wrapped ) #NEWLINE# #UNINDENT# return get_notifier