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:com.krawler.esp.utils.PropsLoader.java

public static Properties loadProperties(String name, ClassLoader loader) {
    if (name == null)
        throw new IllegalArgumentException("null input: name");

    if (name.startsWith("/"))
        name = name.substring(1);/*w  w w  .  j  av  a  2 s  . co  m*/

    if (name.endsWith(SUFFIX))
        name = name.substring(0, name.length() - SUFFIX.length());

    Properties result = null;

    InputStream in = null;
    try {
        if (loader == null)
            loader = ClassLoader.getSystemClassLoader();

        if (LOAD_AS_RESOURCE_BUNDLE) {
            name = name.replace('/', '.');
            // Throws MissingResourceException on lookup failures:
            final ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault(), loader);

            result = new Properties();
            for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) {
                final String key = (String) keys.nextElement();
                final String value = rb.getString(key);

                result.put(key, value);
            }
        } else {
            name = name.replace('.', '/');

            if (!name.endsWith(SUFFIX))
                name = name.concat(SUFFIX);

            // Returns null on lookup failures:
            in = loader.getResourceAsStream(name);
            if (in != null) {
                result = new Properties();
                result.load(in); // Can throw IOException
            }
        }
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        result = null;
    } finally {
        if (in != null)
            try {
                in.close();
            } catch (Throwable ignore) {
                logger.warn(ignore.getMessage(), ignore);
            }
    }

    if (THROW_ON_LOAD_FAILURE && (result == null)) {
        throw new IllegalArgumentException("could not load [" + name + "]" + " as "
                + (LOAD_AS_RESOURCE_BUNDLE ? "a resource bundle" : "a classloader resource"));
    }

    return result;
}

From source file:Main.java

public static String toString(Throwable e) {
    StringWriter w = new StringWriter();
    PrintWriter p = new PrintWriter(w);
    p.print(e.getClass().getName() + ": ");
    if (e.getMessage() != null) {
        p.print(e.getMessage() + "\n");
    }/* w w w.j av  a  2s  . c o m*/
    p.println();
    try {
        e.printStackTrace(p);
        return w.toString();
    } finally {
        p.close();
    }
}

From source file:cn.com.infohold.p2papp.common.gate.OtherUtils.java

public static void trustAllSSLForHttpsURLConnection() {
    // Create a trust manager that does not validate certificate chains
    if (trustAllCerts == null) {
        trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }//from  www  . j  a  v  a  2 s  . c om

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };
    }
    // Install the all-trusting trust manager
    final SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, null);
        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
    }
    HttpsURLConnection
            .setDefaultHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}

From source file:io.servicecomb.swagger.generator.core.unittest.UnitTestSwaggerUtils.java

public static void testException(String expectMsg, SwaggerGeneratorContext context, Class<?> cls,
        String... methods) {// www .j  a v a  2  s.  c  o  m
    Throwable exception = getException(context, cls, methods);
    Assert.assertEquals(expectMsg, exception.getMessage());
}

From source file:org.artifactory.util.HttpClientUtils.java

/**
 * @param e The throwable to inspect for the error message
 * @return Most fitting error message for the given throwable. Tries to prevent empty exception messages.
 *///from  ww  w.j av  a 2  s. c  o m
public static String getErrorMessage(Throwable e) {
    if (e == null) {
        return null;
    }
    String message = e.getMessage(); // default message
    if (e instanceof UnknownHostException) {
        message = "Unknown host - " + e.getMessage();
    } else if (e instanceof ClientProtocolException) {
        // ClientProtocolException doesn't return a message but holds the cause with the message
        if (e.getCause() != null) {
            message = e.getCause().getMessage();
        }
    }
    if (StringUtils.isBlank(message)) {
        message = e.getClass().toString();
    }
    return message;
}

From source file:Main.java

public static String toString(Throwable error) {
    StringBuffer buf = new StringBuffer(512);
    while (error != null) {
        buf.append(error.getClass().getName());
        buf.append(error.getMessage() == null ? "" : error.getMessage());
        buf.append("\r\n");
        StackTraceElement[] stack = error.getStackTrace();
        for (int i = 0; i < stack.length; i++) {
            buf.append("   ");
            buf.append(stack[i].toString());
            buf.append("\r\n");
        }// ww w  .  j av a  2 s .  co m
        if (error.getCause() != null) {
            buf.append("\r\nCaused by :");
        }
        error = error.getCause();
    }
    return buf.toString();
}

From source file:gov.nih.nci.evs.reportwriter.test.lexevs.Util.java

/**
 * Outputs messages to the error log and console, with additional tagging to
 * assist servicability.//from  www.j a va  2 s.  c  o m
 * 
 * @param cause
 *            Error associated with the message.
 */
static void displayAndLogError(Throwable cause) {
    displayAndLogError(cause.getMessage(), cause);
}

From source file:io.servicecomb.swagger.generator.core.unittest.UnitTestSwaggerUtils.java

public static void testException(String expectMsgLevel1, String expectMsgLevel2,
        SwaggerGeneratorContext context, Class<?> cls, String... methods) {
    Throwable exception = getException(context, cls, methods);
    Assert.assertEquals(expectMsgLevel1, exception.getMessage());
    Assert.assertEquals(expectMsgLevel2, exception.getCause().getMessage());
}

From source file:com.basho.riak.presto.cli.CLI.java

public static void dummy_main(String args[]) throws UnknownHostException, InterruptedException {
    System.out.println("foobar");

    RiakNode node = new RiakNode.Builder().withRemoteAddress("127.0.0.1").withRemotePort(8087)
            .withMaxConnections(10).withConnectionTimeout(CONNECTION_TIMEOUT_MIL).build();
    List<RiakNode> nodes = Arrays.asList(node);
    RiakCluster cluster = RiakCluster.builder(nodes).build();

    long startTime = System.currentTimeMillis();

    //Bucket bucket = client.createBucket("demo_bucket").execute();
    for (int i = 0; i < DATA_COUNT; i++) {
        try {// w w  w.jav a  2  s  . c  o m
            if (i % 1000 == 0) {
                log("storing key #" + i);
            }
            ;
            BinaryValue key = BinaryValue.create("demo_key_" + i);
            RiakObject obj = new RiakObject();
            obj.setContentType("application/json");
            obj.setValue(BinaryValue.create("{'name':'bob','age':18}"));
            StoreOperation op = new StoreOperation.Builder(new Location(NAMESPACE, key)).withContent(obj)
                    .withReturnBody(false).build();
            cluster.execute(op);

            op.await();
            if (!op.isSuccess()) {
                throw op.cause();
            }

        } catch (Throwable t) {
            log(t.getMessage());
            log(t.getStackTrace().toString());
        }

    }

    long duration = System.currentTimeMillis() - startTime;

    log("ops per sec: " + DATA_COUNT / (duration / 1000.0));
}

From source file:com.mirth.connect.util.ErrorMessageBuilder.java

public static String buildErrorResponse(String customMessage, Throwable e) {
    String responseException = new String();
    if (e != null) {
        responseException = " [" + e.getClass().getSimpleName() + ": " + e.getMessage() + "]";
    }//from  w w  w  . ja v  a 2s .co m

    return customMessage + responseException;
}