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.qwazr.utils.json.JsonException.java

public JsonException(Status status, String error, Exception e) {
    this.error = error;
    this.reason_phrase = status == null ? null : status.getReasonPhrase();
    this.status_code = status == null ? null : status.getStatusCode();
    Throwable cause = e == null ? null : ExceptionUtils.getRootCause(e);
    this.message = cause == null ? null : cause.getMessage();
    this.exception = cause == null ? null : cause.getClass().getName();
    this.stackTraces = cause == null ? null : ExceptionUtils.getStackTraces(cause);
}

From source file:eu.nubomedia.tutorial.magicmirror.MagicMirrorHandler.java

@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    try {/* w  ww  .jav  a 2s .co m*/
        JsonObject jsonMessage = new GsonBuilder().create().fromJson(message.getPayload(), JsonObject.class);

        log.info("Incoming message: {}", jsonMessage);

        switch (jsonMessage.get("id").getAsString()) {
        case "start":
            start(session, jsonMessage);
            break;
        case "stop": {
            release(session);
            break;
        }
        case "onIceCandidate": {
            onIceCandidate(session, jsonMessage);
            break;
        }
        default:
            error(session, "Invalid message with id " + jsonMessage.get("id").getAsString());
            break;
        }

    } catch (NotEnoughResourcesException e) {
        log.warn("Not enough resources", e);
        notEnoughResources(session);

    } catch (Throwable t) {
        log.error("Exception starting session", t);
        error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
}

From source file:com.microsoft.alm.plugin.idea.common.starters.ApplicationStarterBase.java

@Override
public void main(String[] args) {
    logger.debug("Args passed to VSTS to process: {}", Arrays.toString(args));
    try {/* ww w .  j  a  va 2  s  . co m*/
        if (StringUtils.startsWithIgnoreCase(args[1], URI_PREFIX)) {
            // pass the uri but after removing it's prefix since it isn't needed anymore
            processUri(args[1].replaceFirst(URI_PREFIX, StringUtils.EMPTY));
        } else {
            List<String> argsList = new ArrayList<String>(Arrays.asList(args));
            // remove first arg which is just the generic command "vsts" that got us to this point
            argsList.remove(0);
            processCommand(argsList);
        }
    } catch (Exception e) {
        logger.error(TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_ERRORS_UNEXPECTED, e.getMessage()));
        logMetrics(false, e.getClass().getSimpleName());
        saveAll();

        // exit code IntelliJ uses for exceptions
        System.exit(1);
    } catch (Throwable t) {
        logger.error(TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_ERRORS_UNEXPECTED, t.getMessage()));
        logMetrics(false, t.getClass().getSimpleName());
        saveAll();

        // exit code IntelliJ uses for throwables
        System.exit(2);
    }

    // log metrics and save settings before IDE closes
    logMetrics(true, null);
    saveAll();
}

From source file:org.carewebframework.ui.ExceptionController.java

/**
 * Appends the stack trace for the specified exception to the display.
 * //from   ww  w.j  a  v a 2  s . co  m
 * @param err Exception whose stack trace will be appended.
 */
private void appendStackTrace(final Throwable err) {
    if (err != null) {
        final Class<?> clazz = err.getClass();
        final String msg = err.getMessage();
        //final Throwable cause = err.getCause();//should be null

        this.txtStackTrace.setValue(StringUtils.defaultString(this.txtStackTrace.getValue())
                + StringUtils.trimToEmpty(clazz.getCanonicalName()) + ": " + StringUtils.trimToEmpty(msg)
                + "\n");

        for (final StackTraceElement element : err.getStackTrace()) {
            this.txtStackTrace.setValue(
                    StringUtils.defaultString(this.txtStackTrace.getValue()) + String.valueOf(element) + "\n");
        }
    }
}

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

private Object processMethodFailure(final ProceedingJoinPoint proceedingJoinPoint,
        final String[] exceptionHandlerNames, final Throwable thrownException) throws Throwable {
    final Method handlerMethod = getHandlerMethod(proceedingJoinPoint, thrownException.getClass(),
            exceptionHandlerNames);//from  w  w w .  j av  a2 s.  c  om
    if (handlerMethod != null) {
        logger.trace("Selected handlerMethod : " + handlerMethod.getName());
        try {
            return handlerMethod.invoke(proceedingJoinPoint.getThis(),
                    getExceptionHandlerArgs(thrownException, proceedingJoinPoint.getArgs()));
        } catch (final InvocationTargetException invocationTargetException) {
            throw invocationTargetException.getCause(); // exception thrown by handler method
        }
    } else {
        throw thrownException;
    }
}

From source file:de.berlios.gpon.wui.actions.data.ItemEditAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ItemForm itemForm = (ItemForm) form;

    GponDataDao data = (GponDataDao) getObjectForBeanId("txGponDataDao");

    // this is a newly created hibernate session
    Item item = data.findItemById(itemForm.getItemId());

    // Create a mapped item and
    // inject all form values

    ItemMappedByName itmbn = new ItemMappedByName(item);

    Map map = itemForm.getMap();//from   w w w .ja  v a2  s.  c o m

    Iterator it = map.keySet().iterator();

    while (it.hasNext()) {
        String propName = (String) it.next();

        ItemProperty ip = (ItemProperty) map.get(propName);

        String value = ip.getValue();

        if (value != null && value.trim().length() > 0) {
            try {
                itmbn.setValue(propName, value, ItemMappedByName.INPUT_FORM);
            } catch (Exception ex) {
                saveErrors(request, convertException(ex));
                return mapping.getInputForward();
            }
        } else {
            itmbn.removeValue(propName);
        }
    }

    List associationList = null;

    if (itemForm.getAssMap() != null && itemForm.getAssMap().keySet() != null) {
        associationList = getAssociationList(itmbn.getItem(), itemForm.getAssMap());
    }

    try {
        data.updateItem(itmbn.getItem(), associationList);
    } catch (GponDataDaoException ex) {
        if (ex.getValidationErrors() != null) {
            saveErrors(request, convertValidationErrors(ex.getValidationErrors()));
            return mapping.getInputForward();
        } else {
            // volley
            throw new Exception("Throwing forward.", ex);
        }
    } catch (Throwable t) {
        log.error("Throwable: " + t.getClass().getName() + " m: " + t.getMessage());

        while (t.getCause() != null) {
            t = t.getCause();
            log.error("Throwable: " + t.getClass().getName() + " m: " + t.getMessage());
        }
    }

    return mapping.findForward("success");

}

From source file:com.ns.retailmgr.controller.exception.RestControllerExceptionHandler.java

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {
    Throwable mostSpecificCause = ex.getMostSpecificCause();
    RestErrorMessage RestErrorMessage;//  ww w  .j a va2 s .  c  o m
    if (mostSpecificCause != null) {
        String exceptionName = mostSpecificCause.getClass().getName();
        String message = mostSpecificCause.getMessage();
        RestErrorMessage = new RestErrorMessage(exceptionName, message);
    } else {
        RestErrorMessage = new RestErrorMessage(ex.getMessage());
    }
    return new ResponseEntity(RestErrorMessage, headers, status);
}

From source file:es.us.isa.ideas.app.controllers.AbstractController.java

@ExceptionHandler(Throwable.class)
public ModelAndView panic(Throwable oops) {
    Assert.notNull(oops);//  w  w  w. j a v a 2  s.  com

    ModelAndView result;

    result = new ModelAndView("misc/panic");
    result.addObject("name", ClassUtils.getShortName(oops.getClass()));
    result.addObject("message", oops.getMessage());
    result.addObject("message_type", "message.type.error");
    result.addObject("exception", oops);

    return result;
}

From source file:com.laud.doodo.spring.utils.SpringObjectUtils.java

/**
 * Check whether the given exception is compatible with the exceptions
 * declared in a throws clause./*from  ww  w .  ja va2  s  .c  o  m*/
 * 
 * @param ex
 *            the exception to checked
 * @param declaredExceptions
 *            the exceptions declared in the throws clause
 * @return whether the given exception is compatible
 */
public static boolean isCompatibleWithThrowsClause(Throwable ex, Class<?>[] declaredExceptions) {
    if (!isCheckedException(ex)) {
        return true;
    }
    if (declaredExceptions != null) {
        int i = 0;
        while (i < declaredExceptions.length) {
            if (declaredExceptions[i].isAssignableFrom(ex.getClass())) {
                return true;
            }
            i++;
        }
    }
    return false;
}

From source file:net.joala.condition.timing.WaitFailStrategyTest.java

@Test
public void message_when_failed_with_exception_should_be_contained_in_exception() throws Throwable {
    final S strategy = getFailStrategy();
    boolean success = false;
    final String message = FAIL_MESSAGE_PROVIDER.get();
    try {//from w w w  .j  a  v a 2  s  .c om
        strategy.fail(message, failedFunction, failedInput, lastFailure, CONSUMED_MILLIS_PROVIDER.get());
        success = true;
    } catch (Throwable t) {
        if (!getRaisedExceptionType().isAssignableFrom(t.getClass())) {
            throw t;
        }
        assertThat("Message should be contained in exception message.", t.getMessage(),
                containsString(message));
    }
    assertFalse("An exception should have been thrown.", success);
}