get if 'cause' exists, else return the original exception
768637
private Throwable getCause(Throwable t) {
        Throwable cause = t.getCause();
        if (t.getCause() != null) {
            return cause;
        } else {
            return t;
        }
    }
649689
def exception(self, timeout=None):
        
        if not self._done.wait(timeout):
            raise Timeout('timeout waiting for future')
        if self._state == self.S_EXCEPTION:
            return self._result
996193
def extract_exception(*args):
    

    cls, instance, trcback = sys.exc_info()

    exceptions = filter(lambda x: issubclass(type(x), BaseException), args)
    trcbacks = filter(lambda x: issubclass(type(x), types.TracebackType), args)

    cls, instance = (type(exceptions[0]), exceptions[0]) if exceptions else (cls, instance)
    trcback = trcbacks[0] if trcbacks else trcback

    return cls, instance, trcback
716390
def reraise(self, cause_cls_finder=None):
        """"""
        if self._exc_info:
            six.reraise(*self._exc_info)
        else:
            # Attempt to regenerate the full chain (and then raise
            # from the root); without a traceback, oh well...
            root = None
            parent = None
            for cause in itertools.chain([self], self.iter_causes()):
                if cause_cls_finder is not None:
                    cause_cls = cause_cls_finder(cause)
                else:
                    cause_cls = None
                if cause_cls is None:
                    # Unable to find where this cause came from, give up...
                    raise WrappedFailure([self])
                exc = cause_cls(
                    *cause.exception_args, **cause.exception_kwargs)
                # Saving this will ensure that if this same exception
                # is serialized again that we will extract the traceback
                # from it directly (thus proxying along the original
                # traceback as much as we can).
                exc.__traceback_str__ = cause.traceback_str
                if root is None:
                    root = exc
                if parent is not None:
                    parent.__cause__ = exc
                parent = exc
            six.reraise(type(root), root, tb=None)
633950
public static <T extends Throwable> T findException(Class<T> exceptionTypeToFind, Throwable t) {

    Throwable cause = t;

    while (cause != null)
    {
      if( exceptionTypeToFind.isAssignableFrom( cause.getClass() ) )
      {
        //noinspection unchecked
        return (T)cause;
      }
      if( cause == cause.getCause() )
      {
        return null;
      }
      cause = cause.getCause();
    }

    return null;
  }
305537
def get_exception_message(instance):
    ''''''
    args = getattr(instance, 'args', None)

    if args:
        return str(instance)

    try:
        return type(instance).__name__
    except AttributeError:
        return str(instance)
1213886
public static RuntimeException initCause(RuntimeException ex,
                                             Throwable cause)
    {
        if (Throwable_initCause != null) {
            Object[] args = { cause };
            try {
                Throwable_initCause.invoke(ex, args);
            } catch (Exception e) {
                // Ignore any exceptions
            }
        }
        return ex;
    }
1340182
private boolean isExceptionHandled(String ex) {
        try {
            JavaClass thrownEx = Repository.lookupClass(ex);
            // First look at the throws clause
            ExceptionTable et = getMethod().getExceptionTable();
            if (et != null) {
                String[] throwClauseExNames = et.getExceptionNames();
                for (String throwClauseExName : throwClauseExNames) {
                    JavaClass throwClauseEx = Repository.lookupClass(throwClauseExName);
                    if (thrownEx.instanceOf(throwClauseEx)) {
                        return true;
                    }
                }
            }
            // Next look at the try catch blocks
            CodeException[] catchExs = getCode().getExceptionTable();
            if (catchExs != null) {
                int pc = getPC();
                for (CodeException catchEx : catchExs) {
                    if ((pc >= catchEx.getStartPC()) && (pc <= catchEx.getEndPC())) {
                        int type = catchEx.getCatchType();
                        if (type != 0) {
                            String catchExName = getConstantPool().getConstantString(type, Const.CONSTANT_Class);
                            JavaClass catchException = Repository.lookupClass(catchExName);
                            if (thrownEx.instanceOf(catchException)) {
                                return true;
                            }
                        }
                    }
                }
            }
        } catch (ClassNotFoundException cnfe) {
            bugReporter.reportMissingClass(cnfe);
        }
        return false;
    }
819124
public static String getExceptionCause(final Exception exception) {
		if (exception == null) {
			return "";
		}

		final StringBuilder cause = new StringBuilder();
		Throwable nestedException = (Throwable) exception;
		while (nestedException != null) {
			cause.append("Caused by: ").append(nestedException.toString()).append(" ");
			nestedException = getInnerException(nestedException);
		}

		return cause.toString();
	}
189386
def extern_create_exception(self, context_handle, msg_ptr, msg_len):
    """"""
    c = self._ffi.from_handle(context_handle)
    msg = self.to_py_str(msg_ptr, msg_len)
    return c.to_value(Exception(msg))
332114
def find_actual_cause(self, mechanism, purviews=False):
        """"""
        return self.find_causal_link(Direction.CAUSE, mechanism, purviews)
491435
def _raise_exception(cls, reason, data=None):
    
    text_dict = {
        "error": reason
    }

    if data is not None:
        text_dict["errors"] = data

    raise cls(
        text=json.dumps(text_dict),
        content_type="application/json"
    )
1306633
def get_or_exception(cls, id):
        '''  '''
        obj = cls.get(id)

        if obj is None:
            raise ModelNotFoundError('This object does not exist in database')

        return obj
115617
def add_cause(self, error: Exception):
        ''''''
        self.add_info('Cause error', '{0} - {1}'.format(type(error).__name__, error))
388680
def get_exception_based_on_api_message(message, image_name=""):
    """"""
    msg_bigger_than_source = re.compile('Image was not scaled, is the requested width bigger than the source?')
    msg_does_not_exist = re.compile('The source file .* does not exist')
    msg_does_not_exist_bis = re.compile('<div class="error"><p>Value not found')
    if re.search(msg_bigger_than_source, message):
        msg = "File %s requested at a width bigger than source" % image_name
        return RequestedWidthBiggerThanSourceException(msg)
    elif re.search(msg_does_not_exist, message):
        msg = "File %s does not exist" % image_name
        return FileDoesNotExistException(msg)
    elif re.search(msg_does_not_exist_bis, message):
        msg = "File %s does not exist" % image_name
        return FileDoesNotExistException(msg)
    else:
        return DownloadException(message)
942836
function getErrorStack (ex) {
  let ret = ex.stack || ex.toString()
  if (ex.cause && typeof ex.cause === 'function') {
    const cex = ex.cause()
    if (cex) ret += '\nCaused by: ' + getErrorStack(cex)
  }
  return ret
}
222954
def exception(self, event=None, *args, **kw):
        
        if not self._logger.isEnabledFor(logging.ERROR):
            return

        kw = self._add_base_info(kw)
        kw['level'] = "exception"
        kw.setdefault('exc_info', True)
        return self.error(event, *args, **kw)