parameters: (catch=None, handler=None, exit=True)
return_statement: return decorate
docstring: Very simple decorator that tries any of the exception(s) passed in as
      a single exception class or tuple (containing multiple ones) returning the
      exception message and optionally handling the problem if it rises with the
      handler if it is provided.
  
      So instead of douing something like this::
  
          def bar():
              try:
                  some_call()
                  print("Success!")
              except TypeError, exc:
                  print("Error while handling some call: %s" % exc)
                  sys.exit(1)
  
      You would need to decorate it like this to have the same effect::
  
          @catches(TypeError)
          def bar():
              some_call()
              print("Success!")
  
      If multiple exceptions need to be caught they need to be provided as a
      tuple::
  
          @catches((TypeError, AttributeError))
          def bar():
              some_call()
              print("Success!")
docstring_summary: Very simple decorator that tries any of the exception(s) passed in as
      a single exception class or tuple (containing multiple ones) returning the
      exception message and optionally handling the problem if it rises with the
      handler if it is provided.
docstring_tokens: Very simple decorator that tries any of the exception ( s ) passed in as a single exception class or tuple ( containing multiple ones ) returning the exception message and optionally handling the problem if it rises with the handler if it is provided .
function: def catches(catch=None, handler=None, exit=True):
      """
      Very simple decorator that tries any of the exception(s) passed in as
      a single exception class or tuple (containing multiple ones) returning the
      exception message and optionally handling the problem if it rises with the
      handler if it is provided.
  
      So instead of douing something like this::
  
          def bar():
              try:
                  some_call()
                  print("Success!")
              except TypeError, exc:
                  print("Error while handling some call: %s" % exc)
                  sys.exit(1)
  
      You would need to decorate it like this to have the same effect::
  
          @catches(TypeError)
          def bar():
              some_call()
              print("Success!")
  
      If multiple exceptions need to be caught they need to be provided as a
      tuple::
  
          @catches((TypeError, AttributeError))
          def bar():
              some_call()
              print("Success!")
      """
      catch = catch or Exception
  
      def decorate(f):
  
          @wraps(f)
          def newfunc(*a, **kw):
              try:
                  return f(*a, **kw)
              except catch as e:
                  import logging
                  logger = logging.getLogger('ceph_volume')
                  logger.exception('exception caught by decorator')
                  if os.environ.get('CEPH_VOLUME_DEBUG'):
                      raise
                  if handler:
                      return handler(e)
                  else:
                      sys.stderr.write(make_exception_message(e))
                      if exit:
                          sys.exit(1)
          return newfunc
  
      return decorate
function_tokens: def catches ( catch = None , handler = None , exit = True ) : catch = catch or Exception def decorate ( f ) : @ wraps ( f ) def newfunc ( * a , * * kw ) : try : return f ( * a , * * kw ) except catch as e : import logging logger = logging . getLogger ( 'ceph_volume' ) logger . exception ( 'exception caught by decorator' ) if os . environ . get ( 'CEPH_VOLUME_DEBUG' ) : raise if handler : return handler ( e ) else : sys . stderr . write ( make_exception_message ( e ) ) if exit : sys . exit ( 1 ) return newfunc return decorate