Example usage for java.lang Throwable getClass

List of usage examples for java.lang Throwable getClass

Introduction

In this page you can find the example usage for java.lang Throwable getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.ibm.jaql.lang.expr.core.ExpectExceptionFn.java

@Override
public JsonValue eval(final Context context) throws Exception {
    try {/*from   w ww .  j av  a 2s  .co m*/
        JsonValue value = exprs[0].eval(context);
        throw new RuntimeException("Expected exception but found " + value);
    } catch (Exception ex) {
        if (exprs.length == 1) {
            LOG.info("any exception expected", ex);
            return EXPECTED;
        }
        Throwable cause = ex;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        Class<?> causeClass = cause.getClass();
        for (int i = 1; i < exprs.length; i++) {
            JsonString js = (JsonString) exprs[1].eval(context);
            Class<?> cls = ClassLoaderMgr.resolveClass(js.toString());
            if (cls.isAssignableFrom(causeClass)) {
                LOG.info("exception was expected " + cls.getName().toString(), ex);
                return EXPECTED;
            }
        }
        throw new RuntimeException("expected an exception, but not this one", ex);
    }
}

From source file:com.mmj.app.common.component.ComponentController.java

@ExceptionHandler(Throwable.class)
public ModelAndView handleIOException(Throwable e) throws Throwable {

    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;//from ww  w  . j  ava2  s  .  c o m
    }

    if (request == null && response == null) {
        throw e;
    }

    if (request == null && response != null) {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        OutputStream out = response.getOutputStream();
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8"));
        pw.println("{\"code\":-1,\"message\":\",?!\",\"data\":\"\"}");
        pw.flush();
        pw.close();
    }

    ModelAndView mav = new ModelAndView();
    if (InvokeTypeTools.isAjax(request)) {
        return createJsonMav(",?!", ResultCode.ERROR, e.getMessage());
    }

    mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString());
    mav.addObject("msg", e.getMessage());
    mav.addObject("stackTrace", e.getStackTrace().toString());
    if (request.getRequestURI() != null) {
        mav.addObject("url", request.getRequestURI().toString());
    }
    mav.getModel().put(CustomVelocityLayoutView.USE_LAYOUT, "false");
    mav.setViewName("error");
    return mav;
}

From source file:be.fgov.kszbcss.rhq.websphere.connector.FailFastInvocationHandler.java

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (lastConnectorNotAvailableException != -1
            && System.currentTimeMillis() - lastConnectorNotAvailableException > 120000) {
        log.debug("Resetting lastConnectorNotAvailableException");
        lastConnectorNotAvailableException = -1;
    }//  www. ja  v a 2  s  .  co  m
    if (lastConnectorNotAvailableException == -1) {
        try {
            return method.invoke(target, args);
        } catch (InvocationTargetException invocationTargetException) {
            Throwable exception = invocationTargetException.getCause();
            Throwable t = exception;
            do {
                if (log.isDebugEnabled()) {
                    log.debug("cause = " + t.getClass().getName());
                }
                if (t instanceof ConnectorNotAvailableException) {
                    lastConnectorNotAvailableException = System.currentTimeMillis();
                    break;
                }
                t = t.getCause();
            } while (t != null);
            if (log.isDebugEnabled()) {
                if (lastConnectorNotAvailableException == -1) {
                    log.debug("Not setting lastConnectorNotAvailableException");
                } else {
                    log.debug("Setting lastConnectorNotAvailableException");
                }
            }
            throw exception;
        }
    } else {
        throw new ConnectorNotAvailableException(
                "The connector has been temporarily marked as unavailable because of a previous ConnectorNotAvailableException");
    }
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.FindDevicesSteps.java

@DomainStep("the find devices request is received")
public void whenTheFindDevicesRequestIsReceived()
        throws UnknownEntityException, ValidationException, NotAuthorizedException {
    LOGGER.info("WHEN: \"the the find devices request is received\".");

    try {// ww  w. j  a va2  s.co  m
        this.response = this.deviceManagementEndpoint.findDevices(ORGANISATION_ID, this.request);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
    }
}

From source file:com.clicktravel.cheddar.application.retry.RetryableAspect.java

@Around("@annotation(retryable)")
public Object attemptMethodAndRetryIfNeeded(final ProceedingJoinPoint proceedingJoinPoint,
        final Retryable retryable) throws Throwable {
    int attempts = 0;
    do {/*from  w ww . jav  a2s. co  m*/
        try {
            return proceedingJoinPoint.proceed();
        } catch (final Throwable thrownException) {
            attempts++;
            if (shouldRetryMethod(thrownException.getClass(), retryable, attempts)) {
                Thread.sleep(retryable.retryDelayMillis());
            } else {
                return processMethodFailure(proceedingJoinPoint, retryable.exceptionHandlers(),
                        thrownException);
            }
        }
    } while (true);
}

From source file:br.com.suricattus.surispring.jsf.exception.PrettyExceptionHandler.java

protected boolean handleException(Iterator<ExceptionQueuedEvent> it, Throwable t,
        Class<? extends Throwable> type, String message) {
    if (type.isAssignableFrom(t.getClass())) {
        try {//from   w w  w. ja va  2s .  c om
            if (!catched) {
                FacesContext facesContext = FacesUtils.getContext();

                FacesUtils.addMsgErro(message);
                messagesUtils.saveMessages(facesContext, facesContext.getExternalContext().getSessionMap());

                facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null,
                        "pretty:error");
                facesContext.renderResponse();

                return true;
            }
        } finally {
            catched = true;
            logger.log(Level.SEVERE, t.getLocalizedMessage(), t);
            it.remove();
        }
    }
    return false;
}

From source file:hsa.awp.common.logging.DebugInterceptor.java

/**
 * Logs a thrown exception to the given {@link Logger}.
 *
 * @param log    the {@link Logger} instance to be used for logging.
 * @param method the name of the method.
 * @param t      the thrown Exception/*from   ww w  . j  av  a 2  s. c o m*/
 */
private void logException(Logger log, String method, Throwable t) {

    log.trace("'" + t.getClass().getSimpleName() + "' was thrown in '" + method + "'", t);
}

From source file:io.selendroid.server.SelendroidResponse.java

private JSONObject buildErrorValue(Throwable t) throws JSONException {
    JSONObject errorValue = new JSONObject();
    errorValue.put("class", t.getClass().getCanonicalName());

    // TODO: Form exception in a way that will be unpacked nicely on the local end.
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    t.printStackTrace(printWriter);//from w w  w.j  a va2 s .co m
    errorValue.put("message", t.getMessage() + "\n" + stringWriter.toString());

    /*
     * There is no easy way to attach exception 'cause' clauses here.
     * See workaround above which is used instead.
     */
    //      JSONArray stackTrace = new JSONArray();
    //      for (StackTraceElement el : t.getStackTrace()) {
    //          JSONObject frame = new JSONObject();
    //          frame.put("lineNumber", el.getLineNumber());
    //          frame.put("className", el.getClassName());
    //          frame.put("methodName", el.getMethodName());
    //          frame.put("fileName", el.getFileName());
    //          stackTrace.put(frame);
    //      }
    //      errorValue.put("stackTrace", stackTrace);

    return errorValue;
}

From source file:com.atypon.wayf.request.ResponseWriterTest.java

@Test
public void testLogsError() {
    responseWriter.buildFailure(new RoutingContextMock());

    int statusCode = errorLoggerFacade.getStatusCode();
    Throwable exception = errorLoggerFacade.getException();

    assertEquals(HttpStatus.SC_FAILED_DEPENDENCY, statusCode);
    assertEquals(ServiceException.class, exception.getClass());
}

From source file:com.todo.backend.web.rest.exception.ExceptionResolver.java

@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Throwable.class)
public @ResponseBody ErrorResponse serverError(HttpServletRequest request, Throwable exception) {
    if (log.isErrorEnabled()) {
        log.error(exception.getMessage(), exception);
    }/* w  w  w .  j a v a2s  . co m*/
    return new ErrorResponse(exception.getClass().getSimpleName(), exception.getMessage());
}