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:net.officefloor.plugin.socket.server.http.request.HttpRequestTest.java

/**
 * Create the {@link TestSuite} of the tests to be run.
 * /*w  w  w.  ja v a2s  . c o m*/
 * @return {@link TestSuite} of tests to be run.
 */
public static Test suite() throws Exception {
    // Create the test suite
    TestSuite suite = new TestSuite(HttpRequestTest.class.getName());

    try {

        // Create an instance of the test to obtain test methods
        HttpRequestTest util = new HttpRequestTest(null, null, null, false, null);

        // Obtain the file containing XML Unmarshaller configuration
        File unmarshallerConfigFile = util.findFile(HttpRequestTest.class, "UnmarshallConfiguration.xml");

        // Obtain the current directory
        XmlUnmarshaller unmarshaller = TreeXmlUnmarshallerFactory.getInstance()
                .createUnmarshaller(new FileInputStream(unmarshallerConfigFile));

        // Create the HTTP servicer builder
        HttpServicerBuilder httpServicerBuilder = new HttpServicerBuilder() {
            @Override
            public HttpServicerTask buildServicer(String managedObjectName, MockHttpServer server)
                    throws Exception {
                // Register team to do the work
                server.constructTeam("WORKER", MockTeamSource.createOnePersonTeam("WORKER"));

                // Register the work to process messages
                ReflectiveWorkBuilder workBuilder = server.constructWork(new RequestWork(), "servicer",
                        "service");
                ReflectiveTaskBuilder taskBuilder = workBuilder.buildTask("service", "WORKER");
                taskBuilder.buildObject(managedObjectName);

                // Return the reference to the service task
                return new HttpServicerTask("servicer", "service");
            }
        };

        // Load the non-secure tests
        final MockHttpServer httpServer = new MockHttpServer() {
        };
        loadTests("http", unmarshallerConfigFile.getParentFile(), unmarshaller, httpServer, false,
                httpServicerBuilder, suite);

        // Load the secure tests
        final MockHttpServer httpsServer = new MockHttpServer() {
        };
        httpsServer.setupSecure();
        loadTests("https", unmarshallerConfigFile.getParentFile(), unmarshaller, httpsServer, true,
                httpServicerBuilder, suite);

        // Add a task to shutdown the servers
        suite.addTest(new TestCase("Shutdown HTTP Server") {
            @Override
            protected void runTest() throws Throwable {
                httpServer.shutdown();
                httpsServer.shutdown();
            }
        });

    } catch (Throwable ex) {
        // Add warning that failed to setup
        suite.addTest(TestSuite.warning("Failed setting up suite of tests: " + ex.getMessage() + " ["
                + ex.getClass().getSimpleName() + "]"));
    }

    // Return the test suite
    return suite;
}

From source file:jp.terasoluna.fw.util.ExceptionUtil.java

/**
 * ?????// w ww  .j  av a  2 s .  c  o  m
 * 
 * <p>
 *  ??????????????
 *  ????????
 *  ???getRootCause()????????ServletException??
 * </p>
 *
 * @param throwable 
 * @return ???
 */
public static String getStackTrace(Throwable throwable) {
    StringBuilder sb = new StringBuilder();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    while (throwable != null) {
        baos.reset();
        throwable.printStackTrace(new PrintStream(baos));
        sb.append(baos.toString());

        //throwable?Class??
        Class<? extends Throwable> throwableClass = throwable.getClass();

        // ServletException ?? getRootCause ?
        if (SERVLET_EXCEPTION_NAME.equals(throwableClass.getName())) {
            try {
                //throwable = ((ServletException) throwable).getRootCause()
                //Class??????
                Method method = throwableClass.getMethod(GET_ROOT_CAUSE);
                throwable = (Throwable) method.invoke(throwable);
            } catch (NoSuchMethodException e) {
                //???????
                log.error(e.getMessage());
                throwable = null;
            } catch (IllegalAccessException e) {
                //?????????
                log.error(e.getMessage());
                throwable = null;
            } catch (InvocationTargetException e) {
                //?????
                log.error(e.getMessage());
                throwable = null;
            }

        } else {
            throwable = throwable.getCause();
        }
    }
    return sb.toString();
}

From source file:com.espertech.esper.core.service.ResultDeliveryStrategyImpl.java

/**
 * Handle the exception, displaying a nice message and converting to {@link EPException}.
 * @param logger is the logger to use for error logging
 * @param t is the throwable/*from  w  ww  .j  a  va2s. c  o m*/
 * @param parameters the method parameters
 * @param subscriber the object to deliver to
 * @param method the method to call
 * @throws EPException converted from the passed invocation exception
 */
protected static void handleThrowable(Log logger, Throwable t, Object[] parameters, Object subscriber,
        FastMethod method) {
    String message = "Unexpected exception when invoking method '" + method.getName()
            + "' on subscriber class '" + subscriber.getClass().getSimpleName() + "' for parameters "
            + ((parameters == null) ? "null" : Arrays.toString(parameters)) + " : "
            + t.getClass().getSimpleName() + " : " + t.getMessage();
    logger.error(message, t);
}

From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java

static void displayError(Throwable t) {
    t.printStackTrace();/*ww  w. j  a v  a2  s . c  o m*/
    StringWriter writer = new StringWriter();
    t.printStackTrace(new PrintWriter(writer));
    JOptionPane.showMessageDialog(null, writer.toString(), t.getClass().getSimpleName(),
            JOptionPane.INFORMATION_MESSAGE);
}

From source file:com.qpark.eip.core.ToString.java

private static String getStackTrace(final Throwable t, final boolean isCause) {
    StringBuffer sb = new StringBuffer(1024);
    if (isCause) {
        sb.append("Caused by: ");
    }/*from   www  . j av  a  2 s  .  co  m*/
    sb.append(t.getClass().getName()).append(": ").append(t.getMessage()).append("\n");
    StackTraceElement[] stack = t.getStackTrace();
    int classNameLines = 0;
    int classNameLinesMax = 3;
    boolean printDots = false;
    boolean firstLine = true;
    for (StackTraceElement elem : stack) {
        if (firstLine || elem.getClassName().startsWith(CLASSNAME) && classNameLines <= classNameLinesMax) {
            sb.append("\tat ").append(elem.toString()).append("\n");
            classNameLines++;
            firstLine = false;
            printDots = false;
        } else {
            if (!printDots) {
                sb.append("\tat ...\n");
                printDots = true;
            }
            classNameLines = 0;
        }
    }
    Throwable cause = t.getCause();
    if (cause != null) {
        sb.append(getStackTrace(cause, true));
    }
    return sb.toString();
}

From source file:com.maverick.http.SocketWithLayeredTransport.java

public static String getExceptionMessageChain(Throwable t) {
    StringBuffer buf = new StringBuffer();
    while (t != null) {
        if (buf.length() > 0 && !buf.toString().endsWith(".")) { //$NON-NLS-1$
            buf.append(". "); //$NON-NLS-1$
        }//  w w  w.  ja  v a 2  s  .  c o  m
        if (t.getMessage() != null) {
            buf.append(t.getMessage().trim());
        }
        try {
            Method m = t.getClass().getMethod("getCause", (Class[]) null); //$NON-NLS-1$
            t = (Throwable) m.invoke(t, (Object[]) null);
        } catch (Throwable ex) {
        }
    }
    return buf.toString();
}

From source file:com.salesforce.ide.core.internal.utils.ForceExceptionUtils.java

public static String getRootCauseMessage(Throwable th, boolean exceptionClassPrefix) {
    if (th instanceof ForceConnectionException) {
        return ((ForceConnectionException) th).getExceptionMessage();
    }//  ww w  .j a v a 2s.  co  m

    Throwable rootCauseTh = ForceExceptionUtils.getRootCause(th);
    Throwable finalThrow = (rootCauseTh != null ? rootCauseTh : th);
    String message = NO_EXCEPTION_MESSAGE_MESSAGE;
    if (Utils.isNotEmpty(finalThrow.getMessage())) {
        message = (exceptionClassPrefix ? finalThrow.getClass().getSimpleName() + ": " : "")
                + finalThrow.getMessage();
    } else if (Utils.isNotEmpty(getExceptionMessage(finalThrow))) {
        message = getExceptionMessage(finalThrow);
    }
    return message;
}

From source file:controllers.Common.java

/**
 * Gets a user printable message for an exception.
 * /*from  w  w  w.j a  va2s .  c om*/
 * @param throwable Exception to get the message for
 */
@Util
public static String getUserMessage(Throwable throwable) {
    String message = throwable.getMessage();
    if (message == null) {
        message = throwable.getClass().getName();
    }
    return message;
}

From source file:com.ikanow.aleph2.graph.titan.services.TitanGraphBuilderEnrichmentService.java

/** Utility to check for recoverable errors
 * @param e/* w  w w .j a  v  a  2 s . c o  m*/
 * @return
 */
private static boolean isRecoverableError_internal(Throwable e) {
    // (temporary backend encompasses temporary locking)
    return (PermanentLockingException.class.isAssignableFrom(e.getClass())
            || TemporaryBackendException.class.isAssignableFrom(e.getClass()));

}

From source file:edu.utah.further.ds.impl.advice.QpMonitorAdvice.java

/**
 * @param throwable/*  w  w w. j a va 2  s.  c om*/
 * @return
 */
private static String getExceptionAsString(final Throwable throwable) {
    String exceptionString = throwable.toString();
    if (ReflectionUtil.instanceOf(throwable, ApplicationException.class)) {
        final ApplicationException error = (ApplicationException) throwable;
        if (error.getCode() != null) {
            if (error.getCode().isRecoverable()) {
                exceptionString = throwable.getClass() + ": " + throwable.getMessage();
            }
        }

    }
    return exceptionString;
}