Builds a L{ErrorFault<pyamf.remoting.ErrorFault>} object based on the last
    exception raised.

    If include_traceback is C{False} then the traceback will not be added to
    the L{remoting.ErrorFault}.
170355
def build_fault(cls, e, tb, include_traceback=False):
    
    if hasattr(cls, '_amf_code'):
        code = cls._amf_code
    else:
        code = cls.__name__

    details = None

    if include_traceback:
        details = traceback.format_exception(cls, e, tb)

    return remoting.ErrorFault(code=code, description=unicode(e), details=details)
439819
def send_error(self, error):
        

        error_message = build_raw_error_message(error)
        write_future = self.writer.put(error_message)
        write_future.add_done_callback(
            lambda f: IOLoop.current().add_callback(
                self.tchannel.event_emitter.fire(
                    EventType.after_send_error,
                    error,
                )
            )
        )
        return write_future
615558
def prepare_for_reraise(error, exc_info=None):
    
    if not hasattr(error, "_type_"):
        if exc_info is None:
            exc_info = sys.exc_info()
        error._type_ = exc_info[0]
        error._traceback = exc_info[2]
    return error
411634
def FaultFromZSIException(ex, actor=None):
    '''
    '''
    mystr = getattr(ex, 'str', None) or str(ex)
    mytrace = getattr(ex, 'trace', '')
    elt = '''<ZSI:ParseFaultDetail>
<ZSI:string>%s</ZSI:string>
<ZSI:trace>%s</ZSI:trace>
</ZSI:ParseFaultDetail>
''' % (mystr, mytrace)
    if getattr(ex, 'inheader', 0):
        detail, headerdetail = None, elt
    else:
        detail, headerdetail = elt, None
    return Fault(Fault.Client, 'Unparseable message',
                actor, detail, headerdetail)
663157
def _exception_raise(self):
        
        exc = self.exc_info()[:]
        try:
            exc_type, exc_value, exc_traceback = exc
        except ValueError:
            exc_type, exc_value = exc
            exc_traceback = None

        # raise exc_type(exc_value).with_traceback(exc_traceback)
        if sys.version_info[0] == 2:
            exec("raise exc_type, exc_value, exc_traceback")
        else: #  sys.version_info[0] == 3:
            if isinstance(exc_value, Exception): #hasattr(exc_value, 'with_traceback'):
                # If exc_value is an exception, then just reraise
                exec("raise exc_value.with_traceback(exc_traceback)")
            else:
                # else we'll create an exception using the value and raise that
                exec("raise exc_type(exc_value).with_traceback(exc_traceback)")
30716
function(callback) {
    // capture current error location
    var trace_error = new Error();
    trace_error.id = ERROR_ID++;
    trace_error.__previous__ = current_trace_error;
    trace_error.__trace_count__ = current_trace_error ? current_trace_error.__trace_count__ + 1 : 1;
    limit_frames(trace_error);
    var new_callback = function() {
        current_trace_error = trace_error;
        trace_error = null;
        var res = callback.apply(this, arguments);
        current_trace_error = null;
        return res;
    };
    new_callback.__original_callback__ = callback;
    return new_callback;
}
1006155
def wrap_exception(func: Callable) -> Callable:
    """"""
    try:
        # only do the wrapping if bluepy is installed.
        # otherwise it's pointless anyway
        from bluepy.btle import BTLEException
    except ImportError:
        return func

    def _func_wrapper(*args, **kwargs):
        error_count = 0
        last_error = None
        while error_count < RETRY_LIMIT:
            try:
                return func(*args, **kwargs)
            except BTLEException as exception:
                error_count += 1
                last_error = exception
                time.sleep(RETRY_DELAY)
                _LOGGER.debug('Call to %s failed, try %d of %d', func, error_count, RETRY_LIMIT)
        raise BluetoothBackendException() from last_error

    return _func_wrapper
328523
def error_from_exc(nsdk, tracer_h, e_val=None, e_ty=None):
    """"""

    if not tracer_h:
        return

    if e_ty is None and e_val is None:
        e_ty, e_val = sys.exc_info()[:2]
    if e_ty is None and e_val is not None:
        e_ty = type(e_val)
    nsdk.tracer_error(tracer_h, getfullname(e_ty), str(e_val))
87528
def threw(cls, spy, error_type=None):
        
        cls.__is_spy(spy)
        if not (spy.threw(error_type)):
            raise cls.failException(cls.message)
254269
def set_exception(self, exception, traceback=None):
        
        if not isinstance(exception, BaseException):
            raise RuntimeError("Exception must be of BaseException type")
        self._exception = exception
        self._traceback = traceback
        self._event.set()
        self._invoke_callbacks()
886206
def _create_capture_exceptions(capture_decider: Callable[[BaseException], bool]) -> Callable:
        
        def wrapped(*args, **kwargs):
            result = CaptureWrapBuilder._capture_exceptions(*args, **kwargs)
            if result.exception is not None:
                if not capture_decider(result.exception):
                    raise result.exception
            return result

        return wrapped
426632
def ErrorMsg():
    
    import traceback

    limit = None
    _type, value, tb = sys.exc_info()
    _list = traceback.format_tb(tb, limit) + \
        traceback.format_exception_only(_type, value)
    return "Traceback (innermost last):\n" + "%-20s %s" % (
        " ".join(_list[:-1]),
        _list[-1])
238418
def exception_handler(self, callback):
        
        path = '.'.join([callback.__module__, callback.__name__])
        self._exception_handlers.append(path)
        return callback
904389
def _raiseFindFailed(self, pattern):
        
        event = FindFailedEvent(self, pattern=pattern, event_type="FINDFAILED")

        if self._findFailedHandler is not None:
            self._findFailedHandler(event)
        response = (event._response or self._findFailedResponse)
        if response == "PROMPT":
            response = _findFailedPrompt(pattern)

        if response == "ABORT":
            raise FindFailed(event)
        elif response == "SKIP":
            return False
        elif response == "RETRY":
            return True
1332098
def _defaultErrorHandler(varBinds, **context):
        """"""
        errors = context.get('errors')

        if errors:
            err = errors[-1]
            raise err['error']
1307637
def _error(self, exc_info):
        
        if self.exc_info:
            if self.traceback:
                return exc_info
            return exc_info[:2]
        return exc_info[1]
268795
def handleError(exception, debugFlag=False, abortFlag=True):
    """"""
    if isinstance(exception, CmdError) or not debugFlag:
        error(str(exception))
    else:
        import traceback
        traceback.print_exc()
        error(str(exception))   # or log complete traceback as well?
    if abortFlag:
        sys.exit(1)