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:Main.java

public static void runMain(Object main, String[] args, String defCommand) throws Exception {
    if (args.length > 0) {
        String command = args[0];
        Method[] methods = main.getClass().getMethods();
        for (int i = 0; i < methods.length; i++) {
            Method method = methods[i];
            if (method.getName().equals(command)) {
                String[] remaining = new String[args.length - 1];
                System.arraycopy(args, 1, remaining, 0, remaining.length);
                try {
                    method.invoke(main, bindParameters(method, remaining));
                } catch (InvocationTargetException e) {
                    Throwable cause = e.getCause();
                    if (cause instanceof IllegalArgumentException) {
                        System.err.println("Syntax error: " + cause.getMessage());
                    } else if (cause instanceof Exception) {
                        throw (Exception) cause;
                    } else {
                        throw e;
                    }/*from   www.j a v  a  2s.com*/
                }
                return;
            }
        }
    }
    if (defCommand != null) {
        runMain(main, new String[] { defCommand }, null);
    }
}

From source file:com.redhat.lightblue.util.Error.java

/**
 * Helper that gets a new Error with msg set to the message of the given
 * Throwable.//w  w w  .j  a v a  2 s  .  c o m
 */
public static Error get(String ctx, String errorCode, Throwable e) {
    LOGGER.error(e.getMessage(), e);
    return get(ctx, errorCode, e.getMessage());
}

From source file:com.redhat.lightblue.util.Error.java

/**
 * Helper that gets a new Error with msg set to the message of the given
 * Throwable.//from   w  ww  .j a  va  2  s  .  co  m
 */
public static Error get(String errorCode, Throwable e) {
    LOGGER.error(e.getMessage(), e);
    return get(errorCode, e.getMessage());
}

From source file:Main.java

/**
 * make throwable to string.//from w ww .ja v  a2s .c  o m
 */
public static String toString(Throwable throwable) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    printWriter.print(throwable.getClass().getName() + ": ");
    if (throwable.getMessage() != null) {
        printWriter.print(throwable.getMessage() + "\n");
    }
    printWriter.println();
    try {
        throwable.printStackTrace(printWriter);
        return stringWriter.toString();
    } finally {
        printWriter.close();
    }
}

From source file:de.micromata.genome.gwiki.utils.ClassUtils.java

/**
 * /*  w  ww.  j ava  2  s . c  o m*/
 * @param <T>
 * @param cls
 * @param args must have the exact type
 * @return
 */
public static <T> T createInstance(Class<? extends T> cls, Class<?>[] argTypes, Object... args) {
    try {
        Constructor<? extends T> construktur = cls.getConstructor(argTypes);
        return construktur.newInstance(args);
    } catch (Throwable ex) {
        throw new RuntimeException("Cannot instantiate constructor: " + ex.getMessage(), ex);
    }
}

From source file:com.bstek.dorado.view.resolver.PageOutputUtils.java

public static void outputException(Writer writer, Throwable throwable) throws IOException {
    writer.append("<h1 style=\"font-size:12pt; color:red\">");
    OutputUtils.outputString(writer,//from w w  w. j av a  2 s  . co m
            StringUtils.defaultString(throwable.getMessage(), throwable.getClass().getName()));
    writer.append("</h1>\n");
    writer.append("<ul>\n");
    StackTraceElement[] stes = throwable.getStackTrace();
    for (int i = 0; i < stes.length; i++) {
        StackTraceElement ste = stes[i];
        writer.append("<li>").append("at ");
        OutputUtils.outputString(writer, ste.toString());
        writer.append("</li>\n");
    }
    writer.append("</ul>\n");
}

From source file:com.runwaysdk.logging.RunwayLogUtil.java

public static String getExceptionLoggableMessage(Throwable e) {
    return formatLoggableMessage(e.getMessage(), e.getLocalizedMessage());
}

From source file:com.scsy150.util.OtherUtils.java

public static long getAvailableSpace(File dir) {
    try {// ww w  .  java  2s. c  om
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        LogUtil.e("", e.getMessage());
        return -1;
    }

}

From source file:com.adaptris.mail.MailClientImp.java

protected static MailException wrapException(Throwable e) {
    return wrapException(e.getMessage(), e);
}

From source file:com.google.gerrit.pgm.util.SiteProgram.java

@SuppressWarnings("deprecation")
private static boolean isCannotCreatePoolException(Throwable why) {
    return why instanceof org.apache.commons.dbcp.SQLNestedException && why.getCause() != null
            && why.getMessage().startsWith("Cannot create PoolableConnectionFactory");
}