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:natalia.dymnikova.cluster.ActorLogic.java

@Override
public void receive(final PartialFunction<Object, BoxedUnit> receive) {
    adapter.receive(new AbstractPartialFunction<Object, BoxedUnit>() {
        @Override//ww w  . j ava2  s .  c om
        public BoxedUnit apply(final Object x) {
            if (log.isTraceEnabled()) {
                log.trace("Received message {} from {} to {}", logMessage(x), sender(), self());
            }

            try {
                return receive.apply(x);
            } catch (final Throwable e) {
                log.error("Error {}: '{}' while processing message {} from {} to {}", e.getClass().getName(),
                        e.getMessage(), logMessage(x), sender(), self(), e);

                throw e;
            }
        }

        private Object logMessage(final Object x) {
            final Object msg;
            if (x instanceof Message) {
                final int size = ((Message) x).getSerializedSize();
                if (size < maxLoggingSize.toBytes()) {
                    msg = x.getClass().getName() + ": " + "{" + shortDebugString((Message) x) + "}";
                } else {
                    msg = x.getClass().getName() + ": " + "{too big message for logging " + binaryPrefix(size)
                            + "}";
                }
            } else {
                msg = x;
            }
            return msg;
        }

        @Override
        public boolean isDefinedAt(final Object x) {
            return receive.isDefinedAt(x);
        }
    });

}

From source file:de.lightful.testflux.drools.DroolsRuleTestListener.java

private void addAllFilesFromDirectory(KnowledgeBuilder knowledgeBuilder, String directoryName,
        RulesBaseDirectory ruleBaseDirectory) {
    String baseDirectory = determineBaseDirectory(ruleBaseDirectory);
    File directory = fileFromBaseDirectory(directoryName, baseDirectory);

    if (!directory.exists()) {
        throw new TestFluxException("Directory " + directory.getAbsolutePath() + " given by @"
                + RuleSource.class.getSimpleName() + " must exist (but does not).");
    }//  www  .j a  v  a  2 s . com
    if (!directory.isDirectory()) {
        throw new TestFluxException("Directory " + directory.getAbsolutePath() + " given by @"
                + RuleSource.class.getSimpleName() + " must denote a directory (but does not).");
    }

    Iterator<File> fileIterator = null;
    try {
        fileIterator = FileUtils.iterateFiles(directory, new String[] { "drl" }, false);
    } catch (Throwable t) {
        throw new TestFluxException("Caught " + t.getClass().getSimpleName() + ": " + t.getMessage());
    }

    for (File file : IterableAdapter.makeFrom(fileIterator)) {
        addIndividualFile(knowledgeBuilder, file);
    }
}

From source file:ai.grakn.engine.tasks.manager.TaskState.java

public TaskState markFailed(Throwable exception) {
    this.status = FAILED;
    this.exception = exception.getClass().getName();
    this.stackTrace = getFullStackTrace(exception);
    this.statusChangeTime = now();

    // We want to keep the configuration and checkpoint here
    // It's useful to debug failed states

    return this;
}

From source file:org.trpr.platform.core.impl.management.jmx.JMXNotificationDispatcher.java

/**
 * Convenience method to dispatch Application and System exception details to the JMX sub-system
 * @param exception the Exception details to dispatch to JMX
 *//*from ww w  .j a v a 2s  .  c  o m*/
public void dispatchException(Throwable exception, String source) {
    if (exception != null) {
        StringWriter writer = new StringWriter();
        exception.printStackTrace(new PrintWriter(writer));
        final Notification notification = new Notification(exception.getClass().getName(), source,
                exception.hashCode(), System.currentTimeMillis(),
                getHostIP() + exception.getMessage() + "\n" + writer.toString());
        this.publisher.sendNotification(notification);
        this.exceptionNotificationCount++;
    }
}

From source file:org.jfrog.teamcity.server.global.ArtifactoryGlobalServerConfigController.java

private void handleConnectionException(ActionErrors errors, String url, Exception e) {
    Throwable throwable = e.getCause();
    String errorMessage;/* w w  w .  j a  v  a 2s  .  c  o m*/
    if (throwable != null) {
        errorMessage = e.getMessage() + " (" + throwable.getClass().getCanonicalName() + ")";
    } else {
        errorMessage = e.getClass().getCanonicalName() + ": " + e.getMessage();
    }
    errors.addError("errorConnection", errorMessage);
    Loggers.SERVER.error("Error while testing the connection to Artifactory server " + url, e);
}

From source file:com.ixora.common.ui.ShowExceptionDialog.java

/**
 * @param ex//from   w w w .  j a  va  2 s.c o m
 * @return the last part of the name of the class of the
 * given exception
 */
private String getClassName(Throwable ex) {
    String cn = ex.getClass().getName();
    int idx = cn.lastIndexOf(".");
    if (idx < 0) {
        return cn;
    }
    return cn.substring(++idx);
}

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

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

    // Create String for the response
    String response = null;//from  www .  j  av a2  s  . co m

    // Any exception thrown during object creation will
    // cause failure of the AJAX request
    try {
        IOToolRequestStatus status = TEBackend.getIOConnector().requestTopologyList();

        JSONObject rv = new JSONObject();

        if (status == IOToolRequestStatus.SUCCESS) {
            rv.put("status", AJAXServer.AJAX_SUCCESS);

            Map<String, String> data = TEBackend.getIOConnector().getLastReturnData();

            JSONObject dataJSON = new JSONObject();
            if (data != null) {
                for (Map.Entry<String, String> topoEntry : data.entrySet()) {
                    dataJSON.put(topoEntry.getKey(), topoEntry.getValue());
                }
            }
            rv.put("data", dataJSON);
        } else if (status == IOToolRequestStatus.IOTOOL_BUSY) {
            rv.put("status", AJAXServer.AJAX_ERROR_IOTOOL_BUSY);
        } else {
            rv.put("status", AJAXServer.AJAX_ERROR_GENERAL);
        }

        rv.put("returncode", TEBackend.getIOConnector().getLastReturnCode());
        rv.put("message", TEBackend.getIOConnector().getLastReturnMsg());

        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();
    }

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

From source file:de.metas.ui.web.config.WebuiExceptionHandler.java

private void addStatus(final Map<String, Object> errorAttributes, final RequestAttributes requestAttributes) {
    Integer status = null;/*from  ww  w  .  ja v a  2 s  .co  m*/

    //
    // Extract HTTP status from EXCEPTION_HTTPSTATUS map
    final Throwable error = getError(requestAttributes);
    if (error != null) {
        final Class<? extends Throwable> errorClass = error.getClass();
        status = EXCEPTION_HTTPSTATUS.entrySet().stream().filter(e -> isErrorMatching(e.getKey(), errorClass))
                .map(e -> e.getValue().value()).findFirst().orElse(null);
    }

    //
    // Extract HTTP status from attributes
    if (status == null) {
        status = getAttribute(requestAttributes, RequestDispatcher.ERROR_STATUS_CODE);
    }

    if (status == null) {
        errorAttributes.put(ATTR_Status, 999);
        errorAttributes.put(ATTR_Error, "None");
        return;
    }
    errorAttributes.put(ATTR_Status, status);
    try {
        errorAttributes.put(ATTR_Error, HttpStatus.valueOf(status).getReasonPhrase());
    } catch (final Exception ex) {
        // Unable to obtain a reason
        errorAttributes.put(ATTR_Error, "Http Status " + status);
    }
}

From source file:io.kahu.hawaii.util.spring.HawaiiControllerExceptionHandler.java

@SuppressWarnings("SimplifiableIfStatement")
private boolean mustLog(Throwable throwable) {
    if (throwable instanceof ValidationException) {
        return false;
    }/*ww w. j  a va2 s. com*/
    if (throwable instanceof AuthorisationException) {
        return false;
    }
    return !exceptionsToIgnore.contains(throwable.getClass());
}

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

@DomainStep("the remove device request is received")
public void whenTheRequestIsReceived() {
    LOGGER.info("WHEN: the remove device request is received.");

    try {//  w  w w  . ja v  a2 s .co m
        this.response = this.deviceManagementEndpoint.removeDevice(ORGANISATION_ID, this.request);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}