private static void assertExceptionOccurred( boolean shouldOccur, AbstractExceptionCase exceptionCase, String expectedErrorMsg) throws Throwable { boolean wasThrown = false; try { exceptionCase.tryClosure(); } catch (Throwable e) { if (shouldOccur) { wasThrown = true; final String errorMessage = exceptionCase.getAssertionErrorMessage(); assertEquals(errorMessage, exceptionCase.getExpectedExceptionClass(), e.getClass()); if (expectedErrorMsg != null) { assertEquals("Compare error messages", expectedErrorMsg, e.getMessage()); } } else if (exceptionCase.getExpectedExceptionClass().equals(e.getClass())) { wasThrown = true; System.out.println(""); e.printStackTrace(System.out); fail("Exception isn't expected here. Exception message: " + e.getMessage()); } else { throw e; } } finally { if (shouldOccur && !wasThrown) { fail(exceptionCase.getAssertionErrorMessage()); } } }
private void logTrace(StringBuilder builder, Throwable e) { Throwable parent = e; String indent = " "; while (parent != null) { if (parent == e) { builder.append(indent).append("Trace:").append("\n"); } else { builder .append(indent) .append("Caused By: (") .append(parent.getClass().getSimpleName()) .append(")") .append("\n"); builder .append(indent) .append(" ") .append("[") .append(parent.getMessage()) .append("]") .append("\n"); } for (StackTraceElement ele : e.getStackTrace()) { builder.append(indent).append(" ").append(ele.toString()).append("\n"); } indent += " "; parent = parent.getCause(); } }
private XmlUIElement getXmlUIElementFor(String typeArg) { if (typeToClassMappingProp == null) { setUpMappingsHM(); } String clsName = (String) typeToClassMappingProp.get(typeArg); if ((clsName != null) && !(clsName.equals("*NOTFOUND*")) && !(clsName.equals("*EXCEPTION*"))) { try { Class cls = Class.forName(clsName); return (XmlUIElement) cls.newInstance(); } catch (Throwable th) { typeToClassMappingProp.put(typeArg, "*EXCEPTION*"); showErrorMessage( MessageFormat.format( ProvClientUtils.getString( "{0} occurred when trying to get the XmlUIElement for type : {1}"), new Object[] {th.getClass().getName(), typeArg})); th.printStackTrace(); return null; } } else if (clsName == null) { typeToClassMappingProp.put(typeArg, "*NOTFOUND*"); showErrorMessage( MessageFormat.format( ProvClientUtils.getString( "The type {0} does not have the corresponding XMLUIElement specified in the TypeToUIElementMapping.txt file"), new Object[] {typeArg})); } return null; }
private void populateException(Throwable e) { StringBuilder builder = new StringBuilder(); builder.append("Stack Trace:").append("\n"); builder.append(" Exception: ").append(e.getClass().getSimpleName()).append("\n"); builder.append(" Message: ").append(e.getMessage()).append("\n"); logTrace(builder, e); errorArea.setText(builder.toString()); }
protected void assertNoThrowable(final Runnable closure) { String throwableName = null; try { closure.run(); } catch (Throwable thr) { throwableName = thr.getClass().getName(); } assertNull(throwableName); }
private void handleException(final Throwable ex) { // Ignore CommunicatorDestroyedException which could occur on // shutdown. if (ex instanceof com.zeroc.Ice.CommunicatorDestroyedException) { return; } ex.printStackTrace(); _status.setText(ex.getClass().getName()); }
void printException(Throwable tr) { CAT.error("exception", tr); // StringWriter sw = new StringWriter(); // PrintWriter pw = new PrintWriter(sw); // tr.p rintStackTrace(pw); // pw.flush(); // sw.flush(); log( getMyLoginId() + " reports exception:\r\n " + tr.getClass().getName() + "\r\n " + tr.getMessage()); // sw.toString()); }
private String generateExceptionReport() { StringBuilder builder = new StringBuilder("Spoutcraft Launcher Error Report:\n"); builder.append("( Please submit this report to http://spout.in/issues )\n"); builder.append(" Launcher Build: ").append(Settings.getLauncherBuild()).append("\n"); builder .append("----------------------------------------------------------------------") .append("\n"); builder.append("Stack Trace:").append("\n"); builder.append(" Exception: ").append(cause.getClass().getSimpleName()).append("\n"); builder.append(" Message: ").append(cause.getMessage()).append("\n"); logTrace(builder, cause); builder .append("----------------------------------------------------------------------") .append("\n"); builder.append("System Information:\n"); builder.append(" Operating System: ").append(System.getProperty("os.name")).append("\n"); builder .append(" Operating System Version: ") .append(System.getProperty("os.version")) .append("\n"); builder .append(" Operating System Architecture: ") .append(System.getProperty("os.arch")) .append("\n"); builder .append(" Java version: ") .append(System.getProperty("java.version")) .append(" ") .append(System.getProperty("sun.arch.data.model", "32")) .append(" bit") .append("\n"); builder .append(" Total Memory: ") .append(Runtime.getRuntime().totalMemory() / 1024L / 1024L) .append(" MB\n"); builder .append(" Max Memory: ") .append(Runtime.getRuntime().maxMemory() / 1024L / 1024L) .append(" MB\n"); builder .append(" Memory Free: ") .append(Runtime.getRuntime().freeMemory() / 1024L / 1024L) .append(" MB\n"); builder .append(" CPU Cores: ") .append(Runtime.getRuntime().availableProcessors()) .append("\n"); return builder.toString(); }
/** * {@link RemoteUtil#unwrap(Throwable) unwraps} given exception if possible and builds error * message for it. * * @param e exception to process * @return error message for the given exception */ @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "IOResourceOpenedButNotSafelyClosed"}) @NotNull public static String buildErrorMessage(@NotNull Throwable e) { Throwable unwrapped = RemoteUtil.unwrap(e); String reason = unwrapped.getLocalizedMessage(); if (!StringUtil.isEmpty(reason)) { return reason; } else if (unwrapped.getClass() == GradleApiException.class) { return String.format( "gradle api threw an exception: %s", ((GradleApiException) unwrapped).getOriginalReason()); } else { StringWriter writer = new StringWriter(); unwrapped.printStackTrace(new PrintWriter(writer)); return writer.toString(); } }
/** * Default action when any uncaught exception bubbled from the mouse event handlers of the tools. * Subclass may override it to provide other action. */ protected void handleMouseEventException(Throwable t) { JOptionPane.showMessageDialog( this, t.getClass().getName() + " - " + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); t.printStackTrace(); }
private void handleException(Throwable ex) { ex.printStackTrace(); JOptionPane.showMessageDialog( this, ex.toString(), ex.getClass().getName(), JOptionPane.ERROR_MESSAGE); }