Helper method to encapsulate the logic of enriching the exception with detailed status info.
505028
@InterfaceAudience.Private
    @InterfaceStability.Uncommitted
    public static <X extends CouchbaseException, R extends CouchbaseResponse> X addDetails(X ex, R r) {
        if (r.statusDetails() != null) {
            ex.details(r.statusDetails());
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("{} returned with enhanced error details {}", r, ex);
            }
        }
        return ex;
    }
545989
def last_exception():
    
    exc_type, exc_value, exc_traceback = sys.exc_info()
    return "".join(traceback.format_exception(exc_type, exc_value, exc_traceback))
435878
function setStatus(err) {
    var code = constants.status.UNKNOWN;
    var details = 'Unknown Error';
    var metadata = new Metadata();
    if (err.hasOwnProperty('message')) {
      details = err.message;
    }
    if (err.hasOwnProperty('code')) {
      code = err.code;
      if (err.hasOwnProperty('details')) {
        details = err.details;
      }
    }
    if (err.hasOwnProperty('metadata')) {
      metadata = err.metadata;
    }
    stream.status = {code: code, details: details, metadata: metadata};
  }
205985
private void setPreviousExceptionInfo(Throwable previousException) {
        if (previousException instanceof com.ibm.websphere.exception.DistributedExceptionEnabled) {
            previousExceptionInfo = ((DistributedExceptionEnabled) previousException).getExceptionInfo();
        } else {
            previousExceptionInfo = new DistributedExceptionInfo(previousException);
        }
    }
1262387
def crashlog_status(**kwargs):
    
    ctx = Context(**kwargs)
    ctx.execute_action('crashlog:status', **{
        'storage': ctx.repo.create_secure_service('storage'),
    })
680681
def _set_exception(self):
        """"""
        assert not self.ready()
        self._data = sys.exc_info()
        self._success = False
        self._event.set()
        if self._collector is not None:
            self._collector.notify_ready(self)
81847
def from_exc_info(cls, exc_info=None,
                      retain_exc_info=True,
                      cause=None, find_cause=True):
        """"""
        if exc_info is None:
            exc_info = sys.exc_info()
            if not any(exc_info):
                raise NoActiveException("No exception currently"
                                        " being handled")
        # This should always be the (type, value, traceback) tuple,
        # either from a prior sys.exc_info() call or from some other
        # creation...
        if len(exc_info) != 3:
            raise ValueError("Provided 'exc_info' must contain three"
                             " elements")
        exc_type, exc_val, exc_tb = exc_info
        try:
            if exc_type is None or exc_val is None:
                raise ValueError("Invalid exception tuple (exception"
                                 " type and exception value must"
                                 " be provided)")
            exc_args = tuple(getattr(exc_val, 'args', []))
            exc_kwargs = dict(getattr(exc_val, 'kwargs', {}))
            exc_type_names = utils.extract_roots(exc_type)
            if not exc_type_names:
                exc_type_name = reflection.get_class_name(
                    exc_val, truncate_builtins=False)
                # This should only be possible if the exception provided
                # was not really an exception...
                raise TypeError("Invalid exception type '%s' (not an"
                                " exception)" % (exc_type_name))
            exception_str = utils.exception_message(exc_val)
            if hasattr(exc_val, '__traceback_str__'):
                traceback_str = exc_val.__traceback_str__
            else:
                if exc_tb is not None:
                    traceback_str = '\n'.join(
                        traceback.format_exception(*exc_info))
                else:
                    traceback_str = ''
            if not retain_exc_info:
                exc_info = None
            if find_cause and cause is None:
                cause = cls._extract_cause(exc_val)
            return cls(exc_info=exc_info, exc_args=exc_args,
                       exc_kwargs=exc_kwargs, exception_str=exception_str,
                       exc_type_names=exc_type_names, cause=cause,
                       traceback_str=traceback_str,
                       generated_on=sys.version_info[0:2])
        finally:
            del exc_type, exc_val, exc_tb
1157928
def exception(self, timeout=None, do_raise=True):
    

    with self._lock:
      self.wait(timeout, do_raise=do_raise)
      if not self._exc_info:
        return None
      self._exc_retrieved = True
      if self._cancelled:
        raise self.Cancelled()
      return self._exc_info[1]
1038616
def extract_status_code(error):
    
    try:
        return int(error.code)
    except (AttributeError, TypeError, ValueError):
        try:
            return int(error.status_code)
        except (AttributeError, TypeError, ValueError):
            try:
                return int(error.errno)
            except (AttributeError, TypeError, ValueError):
                return 500
628359
def capture_exception(fn):
    """"""
    def wrapped(*args):
        try:
            return fn(*args)
        except Exception as e:
            return e
    return wrapped
500580
public void printStackTrace() {
        if (detail == null) {
            super.printStackTrace();
        } else {
            synchronized(System.err) {
                System.err.println(super.getMessage() + "; nested exception is:");
                detail.printStackTrace();
            }
        }
    }
836772
def display_error_message(ex) # :nodoc:
      trace "#{name} aborted!"
      display_exception_details(ex)
      trace "Tasks: #{ex.chain}" if has_chain?(ex)
      trace "(See full trace by running task with --trace)" unless
         options.backtrace
    end
617817
function InvalidRequestException(status, description) {
    this.status = status;
    this.description = description;
    this.message = InvalidRequestException.getMessage(status, description);
}
819482
def write_error(self, status_code, **kwargs):
        
        reason = self._reason

        if self.settings.get("serve_traceback") and "exc_info" in kwargs:
            error = []
            for line in traceback.format_exception(*kwargs["exc_info"]):
                error.append(line)
        else:
            error = None
        data = {'_traceback': error, 'message': reason, 'code': status_code}
        content = self.render_exception(**data)
        self.write(content)
185303
def map_exceptions(self, mapping, *args, **kwargs):
        
        @self.__call__(*args, **kwargs)
        def helper(e, status):
            return dict(exception=e), status

        def wrap(target):
            @wraps(target)
            def wrapper(*args, **kwargs):
                try:
                    return target(*args, **kwargs)
                except BaseException as e:
                    for klass, status in mapping:
                        if isinstance(e, klass):
                            return helper(e, status)
                    raise
            return wrapper
        return wrap
687643
def write_error(self, status_code, **kwargs):
        """"""
        message = default_message = httplib.responses.get(status_code, '')
        # HTTPError exceptions may have a log_message attribute
        if 'exc_info' in kwargs:
            (_, exc, _) = kwargs['exc_info']
            if hasattr(exc, 'log_message'):
                message = str(exc.log_message) or default_message
        self.logvalue('halt_reason', message)
        title = "{}: {}".format(status_code, default_message)
        body = "{}: {}".format(status_code, message)
        self.finish("<html><title>" + title + "</title>"
                    "<body>" + body + "</body></html>")
825060
def capture_exception(self, error=None):
        # type: (Optional[BaseException]) -> Optional[str]
        
        client = self.client
        if client is None:
            return None
        if error is None:
            exc_info = sys.exc_info()
        else:
            exc_info = exc_info_from_error(error)

        event, hint = event_from_exception(exc_info, client_options=client.options)
        try:
            return self.capture_event(event, hint=hint)
        except Exception:
            self._capture_internal_exception(sys.exc_info())

        return None