Send @param t and any exception wrapped by @param r to the default uncaught exception handler,
or log them if none such is set up
356011
public static void logExceptionsAfterExecute(Runnable r, Throwable t)
    {
        Throwable hiddenThrowable = extractThrowable(r);
        if (hiddenThrowable != null)
            handleOrLog(hiddenThrowable);

        // ThreadPoolExecutor will re-throw exceptions thrown by its Task (which will be seen by
        // the default uncaught exception handler) so we only need to do anything if that handler
        // isn't set up yet.
        if (t != null && Thread.getDefaultUncaughtExceptionHandler() == null)
            handleOrLog(t);
    }
364029
public static void safelyIgnoreException(Throwable t)
    {
        if (t instanceof ThreadDeath)
        {
            throw (ThreadDeath) t;
        }

        if (t instanceof OutOfMemoryError)
        {
            throw (OutOfMemoryError) t;
        }

    }
479263
private void exception(Throwable e)
    {
        try
        {
            _persistent=false;
            int error_code=HttpResponse.__500_Internal_Server_Error;
            
            if (e instanceof HttpException)
            {
                error_code=((HttpException)e).getCode();
                
                if (_request==null)
                    log.warn(e.toString());
                else
                    log.warn(_request.getRequestLine()+" "+e.toString());
                log.debug(LogSupport.EXCEPTION,e);
            }
            else if (e instanceof EOFException)
            {
                LogSupport.ignore(log,e);
                return;
            }
            else
            {
                _request.setAttribute("javax.servlet.error.exception_type",e.getClass());
                _request.setAttribute("javax.servlet.error.exception",e);
                
                if (_request==null)
                    log.warn(LogSupport.EXCEPTION,e);
                else
                    log.warn(_request.getRequestLine(),e);
            }
            
            if (_response != null && !_response.isCommitted())
            {
                _response.reset();
                _response.removeField(HttpFields.__TransferEncoding);
                _response.setField(HttpFields.__Connection,HttpFields.__Close);
                _response.sendError(error_code);
            }
        }
        catch(Exception ex)
        {
            LogSupport.ignore(log,ex);
        }
    }
788366
public static void throwException(Throwable t) {
        if (hasUnsafe()) {
            PlatformDependent0.throwException(t);
        } else {
            PlatformDependent.<RuntimeException>throwException0(t);
        }
    }
1182970
private void sendErrorMessage(Throwable t) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Sending a 400 for throwable [" + t + "]");
        }
        sendErrorMessage(StatusCodes.BAD_REQUEST);
    }
240215
public static void sendAppUnavailableException(HttpServletRequest req, HttpServletResponse res) throws IOException {
        
        if ((req instanceof SRTServletRequest) && (res instanceof SRTServletResponse)) {
            IRequest ireq = ((SRTServletRequest) req).getIRequest();
            IResponse ires = ((SRTServletResponse) res).getIResponse();
            sendUnavailableException(ireq, ires);
        }
    }
986835
public static void exception(Object o, TraceComponent tc, Throwable t) {
    if(isTracing()) SibTr.exception(o, tc, t);

  }
507592
protected void handleException(Throwable t) {

        if (LOG.isErrorEnabled()) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_JSP_BEAN_0), t);
        }
        if (!(m_isSupressingExceptions || getRequestContext().getCurrentProject().isOnlineProject())) {
            if (LOG.isDebugEnabled()) {
                // no stack trace needed since it was already logged with the "error" log message above
                LOG.debug(
                    Messages.get().getBundle().key(Messages.LOG_DEBUG_INTERRUPTED_EXCEPTION_1, getClass().getName()));
            }
            String uri = null;
            Throwable u = getController().getThrowable();
            if (u != null) {
                uri = getController().getThrowableResourceUri();
            } else {
                uri = getRequestContext().getUri();
            }
            throw new CmsRuntimeException(
                Messages.get().container(Messages.ERR_RUNTIME_1, (uri != null) ? uri : getClass().getName()),
                t);
        }
    }
617489
public final void error(Object message, Throwable t) {
        if (isLevelEnabled(LOG_LEVEL_ERROR)) {
            log(LOG_LEVEL_ERROR, message, t);
        }
    }
617826
public static void sendError( String messageKey, Object[] messageArgs, ServletRequest request,
                                  ServletResponse response, Throwable cause, boolean avoidDirectResponseOutput )
            throws IOException
    {
        assert messageArgs.length == 0 || ! ( messageArgs[0] instanceof Object[] )
                : "Object[] passed to sendError; this is probably a mistaken use of varargs";

        // request may be null because of deprecated FlowController.sendError().
        if ( request != null && avoidDirectResponseOutput )
        {
            String baseMessage = Bundle.getString( messageKey + "_Message", messageArgs );
            throw new ResponseOutputException( baseMessage, cause );
        }

        // Filter the message args to prevent cross-site scripting (XSS) attacks (e.g., if one of the args is something
        // that ultimately came from the user request, and it contains something like <script>[some sscript]</script>.
        for (int i = 0; i < messageArgs.length; i++) {
            Object messageArg = messageArgs[i];
            messageArgs[i] = messageArg != null ? filterValue(messageArg.toString()) : null;
        }
        
        String html = Bundle.getString( messageKey + "_Page", messageArgs );
        response.setContentType( "text/html;charset=UTF-8" );
        response.getWriter().println(html);
        ServletUtils.preventCache( response );
    }
900909
protected final void sendError(Exception e, StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
        sendError(e.getMessage(),req,rsp);
    }
505239
protected void sendErrorToClient(Throwable e, String probeId) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "sendErrorToClient", new Object[] { e, probeId });

        setComplete(true);
        setCurrentlyDoingReceiveWithWait(false);

        StaticCATHelper.sendExceptionToClient(e, probeId, conversation, requestNumber);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "sendErrorToClient");
    }
1241803
public void setException(Throwable t) {
    if (err == null) {
      t.printStackTrace();
    } else {
      err.emit(t);
    }
  }
1168245
@Override
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);
        if (t == null && r instanceof Future<?>) {
            try {
                ((Future<?>) r).get();
            } catch (CancellationException ce) {
                t = ce;
            } catch (ExecutionException ee) {
                t = ee.getCause();
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt(); // ignore/reset
            }
        }
        if (t != null) {
            ARouter.logger.warning(Consts.TAG, "Running task appeared exception! Thread [" + Thread.currentThread().getName() + "], because [" + t.getMessage() + "]\n" + TextUtils.formatStackTrace(t.getStackTrace()));
        }
    }
898287
@Override
    public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
        if (!notifiedOnFailure) {
            notifiedOnFailure = true;
            try {
                responseHandler.onFailure(new SdkClientException("Unable to execute HTTP request.", cause));
            } finally {
                ctx.channel().close();
            }
        }
    }
120170
public static void throwRuntimeException(Throwable t)
    {
        // Unchecked? Can re-throw as is
        throwIfUnchecked(t);
        // Otherwise, let's just change its type:
        throw new RuntimeException("[was "+t.getClass()+"] "+t.getMessage(), t);
    }
239681
public static void main(String[] args) throws Throwable {

        final Exception exceptionToThrowLater = new Exception("Raygun4Java test exception");

        // sets the global unhandled exception handler
        Thread.setDefaultUncaughtExceptionHandler(MyExceptionHandler.instance());

        MyExceptionHandler.getClient().recordBreadcrumb("App starting up");

        RaygunIdentifier userIdentity = new RaygunIdentifier("a@b.com")
                .withEmail("a@b.com")
                .withFirstName("Foo")
                .withFullName("Foo Bar")
                .withAnonymous(false)
                .withUuid(UUID.randomUUID().toString());
        MyExceptionHandler.getClient().setUser(userIdentity);

        new Thread(new Runnable() {
            @Override
            public void run() {
                MyExceptionHandler.getClient().recordBreadcrumb("different thread starting");

                // note that use info not set on this thread

                try {
                    MyExceptionHandler.getClient().recordBreadcrumb("throwing exception");
                    throw exceptionToThrowLater;
                } catch (Exception e) {
                    MyExceptionHandler.getClient().recordBreadcrumb("handling exception");

                    Map<String, String> customData = new HashMap<String, String>();
                    customData.put("thread id", "" + Thread.currentThread().getId());
                    MyExceptionHandler.getClient()
                            .withTag("thrown from thread")
                            .withTag("no user withData")
                            .withData("thread id", "" + Thread.currentThread().getId())
                            .send(exceptionToThrowLater);

                    // this should appear in the raygun console as its already been sed
                    MyExceptionHandler.getClient().recordBreadcrumb("This should not appear because we're sending the same exception on the same thread");
                    Set<String> tags = new HashSet<String>();
                    tags.add("should not appear in console");
                    MyExceptionHandler.getClient().send(exceptionToThrowLater, tags);
                }

                // test offline storage by breaking the proxy
                RaygunSettings.getSettings().setHttpProxy("nothing here", 80);

                System.out.println("No Send below this line");
                MyExceptionHandler.getClient().send(new Exception("occurred while offline offline"));
                System.out.println("No Send above this lines ^");

                // fix the proxy and send offline data
                RaygunSettings.getSettings().setHttpProxy(null, 80);
                MyExceptionHandler.getClient().send(new Exception("This should trigger offline"));

            }
        }).start();

        MyExceptionHandler.getClient().recordBreadcrumb("Throwing exception on main thread");
        throw exceptionToThrowLater;
    }