def capture_exceptions(self, function_or_exceptions=None, **kwargs):
        """
        Wrap a function or code block in try/except and automatically call
        ``.captureException`` if it raises an exception, then the exception
        is reraised.

        By default, it will capture ``Exception``

        >>> @client.capture_exceptions
        >>> def foo():
        >>>     raise Exception()

        >>> with client.capture_exceptions():
        >>>    raise Exception()

        You can also specify exceptions to be caught specifically

        >>> @client.capture_exceptions((IOError, LookupError))
        >>> def bar():
        >>>     ...

        >>> with client.capture_exceptions((IOError, LookupError)):
        >>>    ...

        ``kwargs`` are passed through to ``.captureException``.
        """
        function = None
        exceptions = (Exception,)
        if isinstance(function_or_exceptions, FunctionType):
            function = function_or_exceptions
        elif function_or_exceptions is not None:
            exceptions = function_or_exceptions

        # In python3.2 contextmanager acts both as contextmanager and decorator
        @contextlib.contextmanager
        def make_decorator(exceptions):
            try:
                yield
            except exceptions:
                self.captureException(**kwargs)
                raise

        decorator = make_decorator(exceptions)

        if function:
            return decorator(function)
        return decorator
def capture_exceptions ( self , function_or_exceptions = None , ** kwargs ) : function = None exceptions = ( Exception , ) if isinstance ( function_or_exceptions , FunctionType ) : function = function_or_exceptions elif function_or_exceptions is not None : exceptions = function_or_exceptions @ contextlib . contextmanager def make_decorator ( exceptions ) : try : yield except exceptions : self . captureException ( ** kwargs ) raise decorator = make_decorator ( exceptions ) if function : return decorator ( function ) return decorator
Wrap a function or code block in try/except and automatically call
        ``.captureException`` if it raises an exception, then the exception
        is reraised.

        By default, it will capture ``Exception``

        >>> @client.capture_exceptions
        >>> def foo():
        >>>     raise Exception()

        >>> with client.capture_exceptions():
        >>>    raise Exception()

        You can also specify exceptions to be caught specifically

        >>> @client.capture_exceptions((IOError, LookupError))
        >>> def bar():
        >>>     ...

        >>> with client.capture_exceptions((IOError, LookupError)):
        >>>    ...

        ``kwargs`` are passed through to ``.captureException``.