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:cn.com.sinosoft.util.exception.ExceptionUtils.java

/**
 * <p>//from   ww w . j  a  va 2s .  c o m
 * Finds a <code>Throwable</code> by method name.
 * </p>
 * 
 * @param throwable
 *            the exception to examine
 * @param methodName
 *            the name of the method to find and invoke
 * @return the wrapped exception, or <code>null</code> if not found
 */
private static Throwable getCauseUsingMethodName(Throwable throwable, String methodName) {
    Method method = null;
    try {
        Class<?>[] parameterTypes = {};
        method = throwable.getClass().getMethod(methodName, parameterTypes);
    } catch (NoSuchMethodException ignored) {
        // exception ignored
    } catch (SecurityException ignored) {
        // exception ignored
    }

    if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
        try {
            return (Throwable) method.invoke(throwable, ArrayUtils.EMPTY_OBJECT_ARRAY);
        } catch (IllegalAccessException ignored) {
            // exception ignored
        } catch (IllegalArgumentException ignored) {
            // exception ignored
        } catch (InvocationTargetException ignored) {
            // exception ignored
        }
    }
    return null;
}

From source file:curly.commons.logging.MethodExecutionAspectInterceptor.java

@AfterThrowing(pointcut = "execution(* * (..)) && @annotation(curly.commons.logging.annotation.Loggable)", throwing = "throwable", argNames = "joinPoint,throwable")
public void invokeAfterThrow(JoinPoint joinPoint, Throwable throwable) {
    if (throwableEnable) {
        if (actuatorEnabled && (counterService != null)) {
            String counterName = "counter.threw." + joinPoint.getTarget() + "."
                    + joinPoint.getSignature().getName() + "#" + throwable.getClass().getSimpleName();
            counterService.increment(counterName);
        }//from w  w w .  j av a 2  s  .c  o  m
        log(LogLevel.ERROR, joinPoint.getTarget().getClass(),
                "Error processing method {}, nested exception is {}", joinPoint.getSignature().getName(),
                throwable);
    }
}

From source file:com.crossbusiness.resiliency.aspect.spring.AnnotationCircuitBreakerAspect.java

public Object breakCircuit(final ProceedingJoinPoint pjp, CircuitBreaker circuitBreakerConfig)
        throws Throwable {
    Object result = null;/*w w  w . j a  va2s .  co m*/
    final String method = pjp.getSignature().toLongString();
    CircuitBreakerStatus status = null;
    try {
        final MethodSignature sig = (MethodSignature) pjp.getStaticPart().getSignature();
        registry.registeredMehtodIfnecessary(method, circuitBreakerConfig);
        status = registry.getStatusWithHalfOpenExclusiveLockTry(method);
        if (status.equals(CircuitBreakerStatus.OPEN)) {
            log.info("CIRCUIT STATUS: OPEN. Method {} can not be executed. try later!", method);
            throw new OpenCircuitException();
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN)) {
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN. Another thread has the exclusive lock for half open. Method {} can not be executed.",
                    method);
            throw new OpenCircuitException();
        } else if (status.equals(CircuitBreakerStatus.CLOSED)) {
            log.info("CIRCUIT STATUS: CLOSED. execute method {}", method);
            result = proceed(pjp);
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. This thread win the exclusive lock for the half open call. execute method: {}",
                    method);
            result = proceed(pjp);
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}",
                    method);
            registry.closeAndUnlock(method);
        }

    } catch (CircuitBreakerMethodExecutionException e) {
        Throwable throwable = e.getCause();
        for (Class<? extends Throwable> clazz : registry.getfailureIndications(method)) {
            if (clazz.isAssignableFrom(throwable.getClass())) {
                // detected a failure
                log.info("detected failure. failure indication: {} \nException:", clazz.getCanonicalName(),
                        throwable);
                if (status.equals(CircuitBreakerStatus.CLOSED)
                        && registry.sameClosedCycleInLocalAndGlobaleContext(method)) {
                    log.info("Valid failure: method call and failure are in the same CLOSED cycle.");
                    registry.addFailureAndOpenCircuitIfThresholdAchived(method);
                } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
                    registry.keepOpenAndUnlock(method);
                }
                throw throwable;
            }
        }
        // thrown exception is not a failureIndication
        if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
            log.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}",
                    method);
            registry.closeAndUnlock(method);
        }
        // throw the original method execution exception upper to the method invoker
        throw throwable;
    } finally {
        registry.cleanUp(method);
    }
    return result;
}

From source file:io.curly.commons.logging.MethodExecutionAspectInterceptor.java

@AfterThrowing(pointcut = "execution(* * (..)) && @annotation(io.curly.commons.logging.annotation.Loggable)", throwing = "throwable", argNames = "joinPoint,throwable")
public void invokeAfterThrow(JoinPoint joinPoint, Throwable throwable) {
    if (throwableEnable) {
        if (actuatorEnabled && (counterService != null)) {
            String counterName = "counter.threw." + joinPoint.getTarget() + "."
                    + joinPoint.getSignature().getName() + "#" + throwable.getClass().getSimpleName();
            counterService.increment(counterName);
        }//from w  w w. j a va2  s . c  o m
        log(LogLevel.ERROR, joinPoint.getTarget().getClass(),
                "Error processing method {}, nested exception is {}", joinPoint.getSignature().getName(),
                throwable);
    }
}

From source file:eastwind.webpush.WebPushHandler.java

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    if (cause.getClass().equals(IOException.class)) {
        return;/*from   w w  w .  j  av  a  2 s  . co  m*/
    }
    cause.printStackTrace();
}

From source file:com.greplin.gec.GecLog4jAppender.java

/**
 * Writes a formatted exception to the given writer.
 *
 * @param message   the log message/*from w  ww. j  a va  2 s  . c  o  m*/
 * @param throwable the exception
 * @param level     the error level
 * @param out       the destination
 * @throws IOException if there are IO errors in the destination
 */
void writeFormattedException(final String message, final Throwable throwable, final Level level,
        final Writer out) throws IOException {
    JsonGenerator generator = new JsonFactory().createJsonGenerator(out);

    Throwable rootThrowable = throwable;
    while (this.passthroughExceptions.contains(rootThrowable.getClass()) && rootThrowable.getCause() != null) {
        rootThrowable = rootThrowable.getCause();
    }

    generator.writeStartObject();
    generator.writeStringField("project", this.project);
    generator.writeStringField("environment", this.environment);
    generator.writeStringField("serverName", this.serverName);
    generator.writeStringField("backtrace", ExceptionUtils.getStackTrace(throwable));
    generator.writeStringField("message", rootThrowable.getMessage());
    generator.writeStringField("logMessage", message);
    generator.writeStringField("type", rootThrowable.getClass().getName());
    if (level != Level.ERROR) {
        generator.writeStringField("errorLevel", level.toString());
    }
    writeContext(generator);
    generator.writeEndObject();
    generator.close();
}

From source file:de.decoit.visa.http.ajax.handlers.UpdateTopologyHandler.java

@Override
public void handle(HttpExchange he) throws IOException {
    log.info(he.getRequestURI().toString());

    // Get the URI of the request and extract the query string from it
    QueryString queryParameters = new QueryString(he.getRequestURI());

    // Create String for the response
    String response = null;// www  . jav  a 2 s  . c  o m

    // Check if the query parameters are valid for this handler
    if (this.checkQueryParameters(queryParameters)) {
        // Any exception thrown during object creation will
        // cause failure of the AJAX request
        try {
            TEBackend.TOPOLOGY_STORAGE.setTopologyName(queryParameters.get("name").get());

            JSONObject rv = new JSONObject();
            rv.put("status", AJAXServer.AJAX_SUCCESS);
            response = rv.toString();
        } catch (Throwable ex) {
            TEBackend.logException(ex, log);

            JSONObject rv = new JSONObject();
            try {
                rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION);
                rv.put("type", ex.getClass().getSimpleName());
                rv.put("message", ex.getMessage());
            } catch (JSONException exc) {
                /* Ignore */
            }

            response = rv.toString();
        }
    } else {
        JSONObject rv = new JSONObject();
        try {
            // Missing or malformed query string, set response to error code
            rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS);
        } catch (JSONException exc) {
            /* Ignore */
        }

        response = rv.toString();
    }

    // Send the response
    sendResponse(he, response);
}

From source file:com.telefonica.euro_iaas.paasmanager.manager.async.impl.EnvironmentInstanceAsyncManagerImpl.java

private void updateErrorTask(Task task, String message, Throwable t) {
    TaskError error = new TaskError(message);
    error.setMajorErrorCode(t.getMessage());
    error.setMinorErrorCode(t.getClass().getSimpleName());
    task.setEndTime(new Date());
    task.setStatus(TaskStates.ERROR);// w  ww  .  j av a 2  s  .com
    task.setError(error);
    taskManager.updateTask(task);
    log.error("An error occurs while executing an environment action. See task " + task.getHref()
            + " for more information " + t.getMessage());
}

From source file:de.laures.cewolf.taglib.AbstractChartDefinition.java

/**
 * This method triggers the dataset and chart production. It is only
 * from outside if there is no cached image available in the the
 * image cache.//from   w  w  w. jav  a2 s. c  o m
 */
public Object getChart() throws DatasetProduceException, ChartValidationException, PostProcessingException {
    if (chart == null) {
        chart = produceChart();
        chart.setAntiAlias(antialias);
        if (background != null) {
            Image image = ImageHelper.loadImage(background);
            chart.setBackgroundImage(image);
            chart.setBackgroundImageAlpha(backgroundImageAlpha);
        }
        if (paint != null) {
            chart.setBackgroundPaint(paint);
        }
        if (showLegend) {

            LegendTitle legend = this.getLegend();
            switch (legendAnchor) {
            case ANCHOR_NORTH:
                legend.setPosition(RectangleEdge.TOP);
                break;
            case ANCHOR_WEST:
                legend.setPosition(RectangleEdge.RIGHT);
                break;
            case ANCHOR_EAST:
                legend.setPosition(RectangleEdge.LEFT);
                break;
            default:
                legend.setPosition(RectangleEdge.BOTTOM);
            }
        } else {
            this.removeLegend();
        }
        // postProcessing
        for (int i = 0; i < postProcessors.size(); i++) {
            ChartPostProcessor pp = (ChartPostProcessor) postProcessors.get(i);
            try {
                pp.processChart(chart, (Map) postProcessorsParams.get(i));
            } catch (Throwable t) {
                log.error(t);
                throw new PostProcessingException(t.getClass().getName() + " raised by post processor '" + pp
                        + "'.\nPost processing of this post processor " + "has been ignored.");
            }
        }
    }
    return chart;
}

From source file:cc.kune.core.server.LoggerMethodInterceptor.java

/**
 * Log exception.//  w w w  .jav  a  2 s .  com
 * 
 * @param invocation
 *          the invocation
 * @param e
 *          the e
 */
protected void logException(final MethodInvocation invocation, final Throwable e) {
    final StringBuffer buffer = createBuffer(invocation);
    addMethodName(invocation, buffer);
    buffer.append(" EXCEPTION => ").append(e.getClass()).append(": ")
            .append(e.getCause() != null ? e.getCause() : "")
            .append(e.getMessage() != null ? e.getMessage() : "");
    log(buffer.toString());
}