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:de.appsolve.padelcampus.reporting.ErrorReporter.java

public void notify(Throwable ex) {
    boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString()
            .contains("jdwp");
    if (!isDebug) {
        if (ex != null && !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getClass().getSimpleName())) {
            if (ex.getCause() == null
                    || !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getCause().getClass().getSimpleName())) {
                try {
                    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder
                            .currentRequestAttributes();
                    //log all errors when we don't have a request context, e.g. for scheduled tasks etc
                    if (attr == null || attr.getRequest() == null) {
                        LOG.error(ex.getMessage(), ex);
                    } else {
                        //if we have a request context, ignore bot requests
                        String userAgent = attr.getRequest().getHeader(HttpHeaders.USER_AGENT);
                        if (!StringUtils.isEmpty(userAgent)
                                && !IGNORED_USER_AGENT_PATTERN.matcher(userAgent).matches()) {
                            bugsnag.notify(ex);
                        }//from  w ww.j a  v a 2 s. co  m
                    }
                } catch (IllegalStateException e) {
                    LOG.error(ex.getMessage(), ex);
                }

            }
        }
    }
}

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

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

    // Create String for the response
    String response = null;/*w ww  .ja  va  2s .c  om*/

    // Any exception thrown during object creation will
    // cause failure of the AJAX request
    try {
        TEBackend.closeIOConnector(false);

        JSONObject rv = new JSONObject();
        rv.put("status", AJAXServer.AJAX_SUCCESS);
        response = rv.toString();
    } catch (IOToolException iote) {
        JSONObject rv = new JSONObject();
        try {
            rv.put("status", AJAXServer.AJAX_ERROR_IOTOOL_BUSY);
            response = rv.toString();
        } catch (JSONException exc) {
            /* Ignore */
        }
    } 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();
    }

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

From source file:com.notonthehighstreet.ratel.Honeybadger.java

private boolean ignoreException(final Throwable t) {
    return configuration.getExcludeExceptions().contains(t.getClass().getName());
}

From source file:com.telefonica.euro_iaas.sdc.manager.async.impl.ArtifactAsyncManagerImpl.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 .  ja v a2s  . com
    task.setError(error);
    taskManager.updateTask(task);
    logger.info("An error occurs while executing a product action. See task " + task.getHref()
            + " for more information");
}

From source file:com.xtructure.xutil.test.MethodInfo.java

/**
 * Returns a cell with the exception of the given child.
 * /*from ww  w  .  ja v a2s . c o  m*/
 * @param child
 *            the child, the exception of which should be returned
 * 
 * @return a cell with the exception of the given child
 */
private final String exceptionCell(final InvocationInfo child) {
    final Throwable throwable = child.getResult().getThrowable();
    return ((throwable == null) ? "<td>&nbsp;</td>"
            : String.format("<td><code>%s</code><br />%s</td>", throwable.getClass().getName(),
                    throwable.getMessage()));
}

From source file:com.wavemaker.runtime.server.ServerUtils.java

public static TypedServiceReturn invokeMethodWithEvents(ServiceEventNotifier serviceEventNotifier,
        ServiceWire sw, String method, ParsedServiceArguments args, JSONState jsonState,
        boolean throwExceptions, ServiceResponse serviceResponse) throws WMException {

    TypedServiceReturn ret = null;//from www  .j ava 2 s  . c  o m

    try {
        NDC.push("invoke " + sw.getServiceId() + "." + method);

        Throwable exception = null;

        // log the method arguments after conversion
        if (logger.isDebugEnabled()) {
            StringBuilder logMessage = new StringBuilder();
            logMessage.append("Invoking method \"" + method + "\" with translated parameters: [");

            for (Object arg : args.getArguments()) {
                logMessage.append(arg);
                if (arg != null) {
                    logMessage.append(" (" + arg.getClass() + ")");
                }
                logMessage.append(", ");
            }
            logMessage.append("]");
            logger.debug(logMessage.toString());
        }

        args.setArguments(serviceEventNotifier.executePreOperation(sw, method, args.getArguments()));
        try {
            ret = sw.getServiceType().invokeMethod(sw, method, args, jsonState, serviceResponse);
        } catch (Throwable t) {
            if (throwExceptions) {
                throw new WMRuntimeException(t);
            }

            exception = SystemUtils.unwrapInternalException(t);
        }

        try {
            ret = serviceEventNotifier.executePostOperation(sw, method, ret, exception);
        } catch (Throwable t) {
            if (t instanceof WMException) {
                throw (WMException) t;
            } else if (t instanceof RuntimeException) {
                throw (RuntimeException) t;
            } else {
                // some exception messages are not useful when taken outside
                // of the context of the exception type (ClassCastException,
                // ClassNotFoundException, etc) so include the type in the
                // msg
                String msg = StringUtils.fromLastOccurrence(t.getClass().getName(), ".");
                if (t.getMessage() != null) {
                    msg += ": " + t.getMessage();
                }
                throw new WMRuntimeException(msg, t);
            }
        }
    } finally {
        NDC.pop();
    }

    return ret;
}

From source file:be.wegenenverkeer.common.resteasy.exception.ExceptionUtil.java

/**
 * Extract a "sensible", reasonably compact message.
 *
 * @param exc exception to get message for
 * @return error message/*  w  w  w  . java  2 s  . c om*/
 */
private String getMessage(Throwable exc) {
    String msg;

    // see if there is a "getShortMessage" method
    Class clazz = exc.getClass();
    try {
        Method method = clazz.getMethod("getShortMessage");
        msg = (String) method.invoke(exc);
    } catch (Exception ex) {
        msg = null; /*ignore*/
    }

    // fallback to normal message or else class name
    if (msg == null || "null".equals(msg)) {
        msg = exc.getMessage();
    }
    if (msg == null || "null".equals(msg)) {
        msg = exc.toString();
    }

    return msg;
}

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

@DomainStep("the device's key should be cleared")
public boolean thenTheDeviceKeyShouldBeCleared() {
    LOGGER.info("THEN: \"the device's key should be cleared\".");

    try {/* w ww  . j  a  v  a 2s.c o m*/
        final ArgumentCaptor<OslpDevice> oslpDeviceArgument = ArgumentCaptor.forClass(OslpDevice.class);
        verify(this.oslpDeviceRepositoryMock, timeout(10000).times(1)).save(oslpDeviceArgument.capture());

        Assert.assertEquals("Oslp Devices should match", this.device.getDeviceIdentification(),
                oslpDeviceArgument.getValue().getDeviceIdentification());
        Assert.assertFalse("Oslp Device key should be cleared",
                oslpDeviceArgument.getValue().isPublicKeyPresent());

        final ArgumentCaptor<Ssld> deviceArgument = ArgumentCaptor.forClass(Ssld.class);
        verify(this.ssldRepositoryMock, timeout(10000).times(1)).save(deviceArgument.capture());

        Assert.assertEquals("Devices should match", this.device.getDeviceIdentification(),
                deviceArgument.getValue().getDeviceIdentification());
        Assert.assertFalse("Device key should be cleared", deviceArgument.getValue().isPublicKeyPresent());

    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }

    return true;
}

From source file:org.jetbrains.webdemo.executors.ThrowableSerializer.java

@Override
public void serialize(Throwable throwable, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException, JsonProcessingException {
    jsonGenerator.writeStartObject();/*from  ww  w  .  ja  v a2s .c om*/
    jsonGenerator.writeStringField("message", throwable.getMessage());
    jsonGenerator.writeStringField("fullName", throwable.getClass().getName());
    jsonGenerator.writeObjectField("stackTrace", throwable.getStackTrace());
    jsonGenerator.writeObjectField("cause", throwable.getCause() != throwable ? throwable.getCause() : null);
    jsonGenerator.writeEndObject();
}

From source file:airbrake.Backtrace.java

private String messageIn(final Throwable throwable) {
    String message = throwable.getMessage();
    if (message == null) {
        message = throwable.getClass().getName();
    }// w  w w .  j a va2  s .c o  m
    return message;
}