Example usage for java.lang Throwable getMessage

List of usage examples for java.lang Throwable getMessage

Introduction

In this page you can find the example usage for java.lang Throwable getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:at.alladin.rmbt.qos.testscript.TestScriptInterpreter.java

/**
 * /* w  ww. j a v a  2 s.c o  m*/
 * @param args
 * @return
 * @throws ScriptException
 */
private static Object parse(String[] args, Hstore hstore, Object object, ResultOptions options)
        throws ScriptException {

    if (object == null) {
        throw new ScriptException(ScriptException.ERROR_RESULT_IS_NULL + " PARSE");
    }

    HstoreParser<?> parser = hstore.getParser(object.getClass());

    if (args.length < 1) {
        throw new ScriptException(ScriptException.ERROR_INVALID_ARGUMENT_COUNT + " PARSE: " + args.length);
    }
    if (parser == null) {
        throw new ScriptException(ScriptException.ERROR_PARSER_IS_NULL + " PARSE");
    }

    try {
        Pattern p = PATTERN_ARRAY;
        Matcher m = p.matcher(args[0]);

        if (m.find()) {
            String param = m.group(1);
            int index = Integer.valueOf(m.group(2));
            Object array = parser.getValue(param, object);

            Object indexedObject = null;
            if (array != null) {
                if (List.class.isAssignableFrom(array.getClass())) {
                    indexedObject = ((List<?>) array).get(index);
                } else if (Collection.class.isAssignableFrom(array.getClass())) {
                    Iterator<?> iterator = ((Collection<?>) array).iterator();
                    int counter = 0;
                    while (iterator.hasNext()) {
                        Object o = iterator.next();
                        if ((counter++) == index) {
                            indexedObject = o;
                            break;
                        }
                    }
                }

                if (args.length > 1) {
                    String[] nextArgs = new String[args.length - 1];
                    nextArgs = Arrays.copyOfRange(args, 1, args.length);
                    return parse(nextArgs, hstore, indexedObject, options);
                } else {
                    return indexedObject;
                }
            }
        } else {
            Object value = parser.getValue(args[0], object);
            if (args.length > 1) {
                try {
                    long divisor = Long.parseLong(args[1]);
                    int precision = 2;
                    boolean groupingUsed = false;
                    if (args.length > 2) {
                        precision = Integer.parseInt(args[2]);
                    }
                    if (args.length > 3) {
                        groupingUsed = ("t".equals(args[3].toLowerCase())
                                || "true".equals(args[3].toLowerCase()));
                    }
                    NumberFormat format = (options != null ? DecimalFormat.getInstance(options.getLocale())
                            : DecimalFormat.getInstance());
                    format.setMaximumFractionDigits(precision);
                    format.setGroupingUsed(groupingUsed);
                    format.setRoundingMode(RoundingMode.HALF_UP);
                    //System.out.println("Converting number: " + args[0] + "=" + String.valueOf(value));
                    BigDecimal number = new BigDecimal(String.valueOf(value));
                    return format.format(number.divide(new BigDecimal(divisor)));
                } catch (Exception e) {
                    //can not return parsed element
                }
            }
            //System.out.println("PARAM object: " + args[0] + " -> " + value + " of " + object.toString());
            return value;
        }
    } catch (HstoreParseException e) {
        throw new ScriptException(ScriptException.ERROR_UNKNOWN + " PARSE: " + e.getMessage());
    } catch (Throwable t) {
        throw new ScriptException(ScriptException.ERROR_UNKNOWN + " PARSE: " + t.getMessage());
    }

    return null;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.ProcessRdfForm.java

public static void applyChangesToWriteModel(AdditionsAndRetractions changes, Model queryModel, Model writeModel,
        String editorUri) {//from ww  w  .j  a  v a 2s.  co m
    //side effect: modify the write model with the changes      
    Lock lock = null;
    try {
        lock = writeModel.getLock();
        lock.enterCriticalSection(Lock.WRITE);
        if (writeModel instanceof OntModel) {
            ((OntModel) writeModel).getBaseModel().notifyEvent(new EditEvent(editorUri, true));
        }
        writeModel.add(changes.getAdditions());
        writeModel.remove(changes.getRetractions());
    } catch (Throwable t) {
        log.error("error adding edit change n3required model to in memory model \n" + t.getMessage());
    } finally {
        if (writeModel instanceof OntModel) {
            ((OntModel) writeModel).getBaseModel().notifyEvent(new EditEvent(editorUri, false));
        }
        lock.leaveCriticalSection();
    }
}

From source file:edu.usu.sdl.openstorefront.common.util.StringProcessor.java

/**
 * This will produce html highlighted stacktrace
 *
 * @param throwable//from  www .jav a  2 s  .  co  m
 * @return
 */
public static String parseStackTraceHtml(Throwable throwable) {
    StringBuilder exception = new StringBuilder();

    if (throwable != null) {
        String message = throwable.getMessage();
        if (StringUtils.isNotBlank(message)) {
            exception.append("<b>Message:</b> <span style='color: red;'><b>")
                    .append(message.replace("\n", "<br>")).append("</b><br>");
        }
        for (StackTraceElement stackTraceElement : throwable.getStackTrace()) {
            String style = "color: grey; font-size: 10px;";
            if (stackTraceElement.getClassName().contains("edu.usu.sdl")) {
                style = "color: black; font-size: 12px; font-wieght: bold;";
            }
            exception.append("<span style='").append(style).append("'>")
                    .append(stackTraceElement.getClassName()).append(" (")
                    .append(stackTraceElement.getMethodName()).append(") : ")
                    .append(stackTraceElement.getLineNumber()).append(" ").append("</span><br>");
        }
        if (throwable.getSuppressed().length > 0) {
            exception.append("Suppress Exceptions: ");
            for (Throwable suppressed : throwable.getSuppressed()) {
                exception.append(parseStackTraceHtml(suppressed)).append("<br>");
            }
        }

        if (throwable.getCause() != null) {

        }
    }

    return exception.toString();
}

From source file:com.github.michalbednarski.intentslab.Utils.java

public static String describeException(Throwable exception) {
    String exceptionName = exception.getClass().getName();
    exceptionName = afterLastDot(exceptionName);
    return exceptionName + ": " + exception.getMessage();
}

From source file:com.openkm.servlet.RepositoryStartupServlet.java

/**
 * Close OpenKM and free resources//from   ww  w .  j av  a2  s.co m
 */
public static synchronized void stop(GenericServlet gs) {
    if (!running) {
        throw new IllegalStateException("OpenKM not started");
    }

    // Shutdown plugin framework
    ExtensionManager.getInstance().shutdown();

    try {
        if (Config.REMOTE_CONVERSION_SERVER.equals("")) {
            if (!Config.SYSTEM_OPENOFFICE_PATH.equals("")) {
                log.info("*** Shutting down OpenOffice manager ***");
                DocConverter.getInstance().stop();
            }
        }
    } catch (Throwable e) {
        log.warn(e.getMessage(), e);
    }

    log.info("*** Shutting down UI Notification... ***");
    uin.cancel();

    log.info("*** Shutting down cron... ***");
    cron.cancel();

    if (Config.UPDATE_INFO) {
        log.info("*** Shutting down update info... ***");
        ui.cancel();
    }

    // Cancel timers
    cronTimer.cancel();
    uinTimer.cancel();
    uiTimer.cancel();

    // Shutdown pending task executor
    log.info("*** Shutting pending task executor... ***");
    PendingTaskExecutor.shutdown();

    log.info("*** Shutting down repository... ***");

    try {
        // Preserve system user config
        if (!Config.REPOSITORY_NATIVE) {
            JcrRepositoryModule.shutdown();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

    log.info("*** Repository shutted down ***");

    try {
        log.info("*** Execute stop script ***");
        File script = new File(Config.HOME_DIR + File.separatorChar + Config.STOP_SCRIPT);
        ExecutionUtils.runScript(script);
        File jar = new File(Config.HOME_DIR + File.separatorChar + Config.STOP_JAR);
        ExecutionUtils.getInstance().runJar(jar);
    } catch (Throwable e) {
        log.warn(e.getMessage(), e);
    }

    try {
        log.info("*** Execute stop SQL ***");
        File sql = new File(Config.HOME_DIR + File.separatorChar + Config.STOP_SQL);

        if (sql.exists() && sql.canRead()) {
            FileReader fr = new FileReader(sql);
            HibernateUtil.executeSentences(fr);
            IOUtils.closeQuietly(fr);
        } else {
            log.warn("Unable to read sql: {}", sql.getPath());
        }
    } catch (Throwable e) {
        log.warn(e.getMessage(), e);
    }

    log.info("*** Shutting down workflow engine... ***");
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    jbpmContext.getJbpmConfiguration().getJobExecutor().stop();
    jbpmContext.getJbpmConfiguration().close();
    jbpmContext.close();

    // OpenKM is stopped
    running = false;
}

From source file:com.anaplan.connector.MulesoftAnaplanResponse.java

/**
 * Usually as a last resort to error-logging, whenever the cause of the
 * error is unknown and everything needs to be brought to a grinding halt.
 * In order to stop the flow, the Throwable is wrapped into a
 * AnaplanOperationException.//from   www.  j  a  va 2s  .  co  m
 *
 * @param connection Anaplan API connection.
 * @param e Throwable object containing Failure info
 * @param reason Reason for Epic Fail
 * @throws AnaplanOperationException Internal operation exception for
 *      signalling epic fail.
 */
public static void responseEpicFail(AnaplanConnection connection, Throwable e, String reason)
        throws AnaplanOperationException {
    final String msg;
    if (reason == null) {
        msg = "Unexpected operation error: Generating OperationResponse " + "error for " + e.getMessage();
    } else {
        msg = reason + ": " + e.getMessage();
    }

    logger.error(msg, e); // for stack trace
    throw new AnaplanOperationException(e.getMessage());
}

From source file:it.govpay.core.utils.RtUtils.java

private static byte[] validaFirmaXades(byte[] rt, String idDominio) throws NdpException {
    try {//from   www  .  java2 s.co  m
        return SignUtils.cleanXadesSignedFile(rt);
    } catch (Throwable e) {
        throw new NdpException(FaultPa.PAA_FIRMA_ERRATA, idDominio, e.getMessage());
    }
}

From source file:it.govpay.core.utils.RtUtils.java

private static byte[] validaFirmaCades(byte[] rt, String idDominio) throws NdpException {
    try {/*ww w.  ja  v  a 2 s  .  co m*/
        return SignUtils.cleanCadesSignedFile(rt);
    } catch (Throwable e) {
        throw new NdpException(FaultPa.PAA_FIRMA_ERRATA, idDominio, e.getMessage());
    }
}

From source file:com.evolveum.midpoint.provisioning.util.ProvisioningUtil.java

public static void recordFatalError(Trace logger, OperationResult opResult, String message, Throwable ex) {
    if (message == null) {
        message = ex.getMessage();
    }/*from  w  w w .  j  a  va 2s .  c  om*/
    logger.error(message, ex);
    opResult.recordFatalError(message, ex);
    opResult.cleanupResult(ex);
}

From source file:edu.samplu.common.WebDriverUtil.java

public static void jGrowlException(Throwable t) {
    String failMessage = t.getMessage() + "\n" + ExceptionUtils.getStackTrace(t);
    System.out.println("jGrowl failure " + failMessage);
    if (JGROWL_ERROR_FAILURE) {
        SeleneseTestBase.fail(failMessage);
    }//w w w. j  a va 2 s .  c o m
}