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.tudarmstadt.lt.ltbot.postprocessor.DecesiveValueLogger2.java

@Override
protected void innerProcess(CrawlURI uri) throws InterruptedException {
    LOG.finest(String.format("[%s (%s): %s via %s]: %s; %s;", getBeanName(), getExtraInfoValueFieldName(), uri,
            uri.getVia(), uri.getExtraInfo(),
            uri.getFullVia() != null ? uri.getFullVia().getExtraInfo() : "{}"));
    JSONObject info = uri.getExtraInfo();
    try {/*from   w  w w .j av a2 s  .c  o  m*/
        synchronized (_w) {
            if (!(info.has(EXTRA_INFO_PLAINTEXT_ABBREVIATED) || uri.getVia() != null))
                return;/* DO NOT WRITE ANYTHING */
            if (info.has(EXTRA_INFO_PLAINTEXT_ABBREVIATED))
                /* decision value was computed on the current document */
                writeInformationFromCurrentURI(uri, info);
            else
                /* decision value was computed on the preceding document */
                writeInformationFromPrecedingURI(uri);
            _w.flush();
        }
    } catch (Throwable t) {
        for (int i = 1; t != null && i < 10; i++) {
            LOG.log(Level.WARNING,
                    String.format("Failed to write decesive value from extra info to file (%d-%s:%s).", i,
                            t.getClass().getName(), t.getMessage()),
                    t);
            t = t.getCause();
        }
    }
}

From source file:fr.litarvan.commons.crash.ExceptionHandler.java

public void handle(Throwable throwable) {
    if (!Canceller.chain(c -> {
        triggers.forEach(trigger -> trigger.trigger(this, throwable, c));
        specificTriggers.entrySet().stream().filter(entry -> entry.getKey() == throwable.getClass())
                .forEach(entry -> entry.getValue().trigger(this, throwable, c));
    })) {/*from  w  ww .j ava  2 s.c o  m*/
        return;
    }

    String report = makeCrashReport(throwable);

    System.err.println("\n##! Exception caught !##\n");
    System.err.println(report);

    if (crashFolder != null) {
        File file = new File(crashFolder, "crash-" + System.currentTimeMillis());
        System.err.println("=> Saving crash report to " + file.getAbsolutePath());

        try {
            FileUtils.write(file, report, Charset.defaultCharset());
        } catch (IOException e) {
            throw new RuntimeException("Couldn't save the crash report !", e);
        }
    }
}

From source file:com.graphhopper.http.GraphHopperServlet.java

String errorsToXML(List<Throwable> list) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();
    Element gpxElement = doc.createElement("gpx");
    gpxElement.setAttribute("creator", "GraphHopper");
    gpxElement.setAttribute("version", "1.1");
    doc.appendChild(gpxElement);/*  w w  w  .  j  a v a2s .  c  o m*/

    Element mdElement = doc.createElement("metadata");
    gpxElement.appendChild(mdElement);

    Element errorsElement = doc.createElement("extensions");
    mdElement.appendChild(errorsElement);

    for (Throwable t : list) {
        Element error = doc.createElement("error");
        errorsElement.appendChild(error);
        error.setAttribute("message", t.getMessage());
        error.setAttribute("details", t.getClass().getName());
    }
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    StringWriter writer = new StringWriter();
    transformer.transform(new DOMSource(doc), new StreamResult(writer));
    return writer.toString();
}

From source file:fit.Fixture.java

public void exception(Parse cell, Throwable exception) {
    while (exception.getClass().equals(InvocationTargetException.class)) {
        exception = ((InvocationTargetException) exception).getTargetException();
    }//www. j a v  a 2  s . com
    if (isFriendlyException(exception)) {
        cell.addToBody("<hr/>" + label(exception.getMessage()));
    } else {
        final StringWriter buf = new StringWriter();
        exception.printStackTrace(new PrintWriter(buf));
        cell.addToBody("<hr><pre><div class=\"fit_stacktrace\">" + (buf.toString()) + "</div></pre>");
    }
    cell.addToTag(" class=\"error\"");
    counts.exceptions++;
}

From source file:de.decoit.visa.http.ajax.handlers.ExportRDFHandler.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 StringBuilder for the response
    String response = null;/*w w  w .j  a va 2 s  . c  om*/

    // Check if the query parameters are valid for this handler
    if (this.checkQueryParameters(queryParameters)) {
        try {
            Path outFile = TEBackend.getExportPath().resolve(queryParameters.get("file").get());

            TEBackend.RDF_MANAGER.writeRDF(outFile);

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

            // Exception was thrown during cable removal
            JSONObject rv = new JSONObject();
            try {
                rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION);
                rv.put("type", ex.getClass().getSimpleName());
                rv.put("message", ex.getMessage());
                rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON());
            } catch (JSONException e) {
                /* Ignore */
            }

            response = rv.toString();
        }
    } else {
        // Missing or malformed query string, set response to error code
        JSONObject rv = new JSONObject();
        try {
            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.webbfontaine.valuewebb.action.fcvr.FCVRSendScheduler.java

@Asynchronous
public QuartzTriggerHandle scheduleTask(@Expiration Date when, @IntervalCron String interval) {
    LOGGER.info("Started");

    long startTime = System.currentTimeMillis();

    synchronized (LOCK) { // allow only one async thread to do this

        EntityManager entityManager = (EntityManager) Component.getInstance("entityManager",
                ScopeType.STATELESS, true);
        List<Long> ttIDs = Utils.setDirectRead(entityManager.createNamedQuery(findSentTTIdsCI)).getResultList();

        LOGGER.debug("Found Sent TTs: {0}}", ttIDs);

        if (ttIDs.isEmpty()) {
            return null;
        }/* www. jav a  2 s .c  o m*/

        if (!AuthenticatorBean.getDaemonIdentity().tryLogin()) {
            LOGGER.error("Can not login with 'daemon' identity to update TTs");
            return null;
        }
        try {

            for (Long ttId : ttIDs) {
                try {
                    TtGen ttGen = entityManager.find(TtGen.class, ttId);

                    LOGGER.debug("TT to sent to FCVR: {0}, status {1}", ttId, ttGen.getStatus());

                    if (!ttGen.getStatus().equals(TT_SENT)) { // already processed by other thread
                        continue;
                    }

                    new TTDataLoader(ttGen).processAll();

                    Message message = FCVRSender.getInstance().sendFCVR(ttGen);

                    if (FCVRHelper.transactionError(message)) {
                        LOGGER.error("SOGate respond with error for TT {0} with FCVR Number {1}. Error: {2}",
                                ttId, ttGen.getFcvrNum(), message.getProperties());
                        FCVRHelper.logExceptions(ttId, message);
                    } else {
                        if (FCVRHelper.transactionFailed(message)) {
                            FCVRHelper.logExceptions(ttId, message);

                            String remoteExceptionMessage = FCVRHelper.extractErrors(message);
                            FCVRHelper.appendErrorsToTT(ttGen, remoteExceptionMessage);

                            if (isFCVRAlreadyExists(remoteExceptionMessage)) {
                                LOGGER.warn(
                                        "FCVR already exists for TT with ID {0}, check logs for previous unexpected errors. TT status will be changed to Sent Ok.",
                                        ttId);
                                updateTT(ttGen, RESPONSE_OK); // ignore existance and change the status.
                            } else {
                                if (isAccessProblem(remoteExceptionMessage)) {
                                    LOGGER.warn(
                                            "Cannot complete transaction for FCVR document, got {0} for TT ID: {1}, document processing skipped.",
                                            remoteExceptionMessage, ttId);
                                } else {
                                    LOGGER.info(
                                            "Cannot complete transaction for FCVR document, TT ID: {0}, document status will be changed accordingly.",
                                            ttId);
                                    updateTT(ttGen, ERROR_RESPONSE);
                                }
                            }

                        } else {
                            if (FCVRHelper.transactionSucceeded(message)) {
                                LOGGER.info("FCVR transaction on TT {0} completed successfully", ttId);
                                updateTT(ttGen, RESPONSE_OK);
                            } else {
                                LOGGER.error("Unknown FCVR response for TT: {0}, message: {1}", ttId,
                                        message.getProperties());
                                throw new FCVRProcessingException(
                                        "Unknown FCVR reponse, remote document change is ");
                            }
                        }
                    }
                } catch (FCVRProcessingException e) {
                    Throwable cause = e.getCause();
                    if (isConnectionProblem(cause) || isLoginProblem(cause)) {
                        LOGGER.warn("{0}: Can not connect to TWM-FCVR. {1}", cause.getClass().getName(),
                                cause.getMessage());
                        break; // do not continue with next TT if connection problem
                    } else {
                        LOGGER.error("", e);
                    }
                }
            }
        } finally {
            AuthenticatorBean.getDaemonIdentity().logout();
        }
        LOGGER.debug("Processing took {0} ms", System.currentTimeMillis() - startTime);
        return null;
    }
}

From source file:com.haulmont.cuba.web.exception.DefaultExceptionHandler.java

protected void showNotification(App app, Throwable exception) {
    Throwable rootCause = ExceptionUtils.getRootCause(exception);
    if (rootCause == null) {
        rootCause = exception;/* www  .  j ava2s .  c  o  m*/
    }
    WebWindowManager windowManager = app.getWindowManager();
    if (windowManager != null) {
        windowManager.showNotification(messages.getMainMessage("exceptionDialog.caption", app.getLocale()),
                rootCause.getClass().getSimpleName()
                        + (rootCause.getMessage() != null ? "\n" + rootCause.getMessage() : ""),
                Frame.NotificationType.ERROR);
    }
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void showConnectionError(Activity activity, Throwable t, boolean allowContinue) {
    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "showConnectionError " + AndroidUtils.getCompressedStackTrace(t, 0, 9));
    }//  w ww.j a v  a2  s  .  co  m

    Throwable t2 = (t instanceof RPCException) ? t.getCause() : t;

    if ((t2 instanceof HttpHostConnectException) || (t2 instanceof UnknownHostException)) {
        String message = t.getMessage();
        if (AndroidUtils.DEBUG) {
            Log.d(TAG, "showConnectionError Yup " + message);
        }
        if (message != null && message.contains("pair.vuze.com")) {
            showConnectionError(activity, R.string.connerror_pairing, allowContinue);
            return;
        }
    }
    String message = "";
    while (t != null) {
        String newMessage = t.getMessage();
        if (newMessage != null && message.contains(newMessage)) {
            t = t.getCause();
            continue;
        }
        message += newMessage + "\n";
        Throwable tReplace = t;
        while (tReplace != null) {
            Class<?> cla = tReplace.getClass();
            String name = cla.getName();
            message = message.replaceAll(name + ": ", cla.getSimpleName() + ": ");
            tReplace = tReplace.getCause();
        }
        t = t.getCause();
    }
    showConnectionError(activity, message, allowContinue);
}

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

@DomainStep("the retrieve event notification request is received")
public void whenTheRetrieveEventNotificationRequestIsReceived() {
    LOGGER.info("WHEN: the retrieve event notification request is received");

    try {/*from  w  w  w .  ja  v a2 s.  co  m*/
        // Send the find events request.
        this.response = this.deviceManagementEndpoint
                .findEventsRequest(this.organisation.getOrganisationIdentification(), this.request);
        if (this.response == null) {
            LOGGER.info("Response is null");
        }
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}\nStacktrace: {}", t.getClass().getSimpleName(), t.getMessage(),
                t.getStackTrace());
    }
}

From source file:com.telefonica.euro_iaas.sdc.manager.async.impl.ProductInstanceAsyncManagerImpl.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);//from w ww .  j  a  v  a 2  s.  co  m
    task.setError(error);
    taskManager.updateTask(task);
    LOGGER.info("An error occurs while executing a product action. See task " + task.getHref()
            + "for more information");
}