List of usage examples for java.lang Exception getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.oncore.calorders.core.utils.FormatHelper.java
/** * This method returns the stack trace of an exception * * @param ex The exception/* w w w . j av a2s .c o m*/ * @return The stack trace in string */ public static String getStackTrace(Exception ex) { StringBuilder trace = new StringBuilder(); trace.append(ex.getClass().getCanonicalName()); trace.append("\n\t"); trace.append(ex.getMessage()); trace.append("\n"); for (StackTraceElement stackTrace : ex.getStackTrace()) { trace.append(stackTrace.toString()); trace.append("\n\t"); } return trace.toString(); }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java
public static String elementToString(Node n) throws Exception { try {//from www. j a v a 2s .c om String name = n.getNodeName(); short type = n.getNodeType(); if (Node.CDATA_SECTION_NODE == type) { return "<![CDATA[" + n.getNodeValue() + "]]>"; } if (name.startsWith("#")) { return ""; } StringBuffer sb = new StringBuffer(); sb.append('<').append(name); NamedNodeMap attrs = n.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); sb.append(' ').append(attr.getNodeName()).append("=\"").append(attr.getNodeValue()) .append("\""); } } String textContent = null; NodeList children = n.getChildNodes(); if (children.getLength() == 0) { if ((textContent = n.getTextContent()) != null && !"".equals(textContent)) { sb.append(textContent).append("</").append(name).append('>'); } else { sb.append("/>").append('\n'); } } else { sb.append('>').append('\n'); boolean hasValidChildren = false; for (int i = 0; i < children.getLength(); i++) { String childToString = elementToString(children.item(i)); if (!"".equals(childToString)) { sb.append(childToString); hasValidChildren = true; } } if (!hasValidChildren && ((textContent = n.getTextContent()) != null)) { sb.append(textContent); } sb.append("</").append(name).append('>'); } return sb.toString(); } catch (Exception e) { log.error(e); log.error(e.getStackTrace()); throw (e); } }
From source file:com.tc.stats.DSO.java
private static Exception newPlainException(Exception e) { String type = e.getClass().getName(); if (type.startsWith("java.") || type.startsWith("javax.")) { return e; } else {//from w ww . j a v a 2 s .co m RuntimeException result = new RuntimeException(e.getMessage()); result.setStackTrace(e.getStackTrace()); return result; } }
From source file:de.prozesskraft.pkraft.Manager.java
private static void exiterException(String pathToInstance, Exception e) { try {/* ww w.j a va2 s. com*/ java.io.FileWriter writer = new FileWriter(pathToInstance + ".pkraft-manager.stacktrace", true); writer.write(new Timestamp(System.currentTimeMillis()).toString() + "\n"); writer.write(e.getMessage() + "\n"); writer.write(e.getStackTrace() + "\n"); writer.write("--------------" + "\n"); writer.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } exit = true; System.exit(1); }
From source file:org.opendaylight.fpc.utils.eventStream.EventClient.java
/** * Send HttpRequest to Client//from w w w .j a v a 2s .c o m * @param uri - FPC Client Uri */ public void connectToClient(String uri) { this.clientUri = uri; try { client.start(); HttpAsyncRequestProducer get = HttpAsyncMethods.createGet(this.clientUri); client.execute(get, new MyResponseConsumer(this.clientUri), null); } catch (Exception e) { ErrorLog.logError(e.getStackTrace()); } }
From source file:com.gtwm.pb.servlets.ServletUtilMethods.java
/** * Return a string for logging purposes, of an exception's 'cause stack', * i.e. the original exception(s) thrown and stack trace, i.e. the methods * that the exception was thrown through. * /*from www . ja v a 2 s . co m*/ * Called by logException */ private static String getExceptionCauses(Exception ex) { String errorMessage = ex.toString() + "\r\n"; if (ex.getCause() != null) { // Recursively find causes of exception errorMessage += " - Error was due to..."; Exception exceptionCause = ex; String causeIndent = " - "; errorMessage += causeIndent + ex.toString() + "\r\n"; while (exceptionCause.getCause() != null) { if (exceptionCause.getCause() instanceof Exception) { exceptionCause = (Exception) exceptionCause.getCause(); causeIndent += " - "; errorMessage += causeIndent + getExceptionCauses(exceptionCause); } } } // Include out relevant parts of the stack trace StackTraceElement[] stackTrace = ex.getStackTrace(); if (stackTrace.length > 0) { errorMessage += " - Stack trace:\r\n"; int nonGtwmClassesLogged = 0; for (StackTraceElement stackTraceElement : stackTrace) { if (!stackTraceElement.getClassName().startsWith("com.gtwm.")) { nonGtwmClassesLogged++; } // Only trace our own classes + a few more, stop shortly after // we get to java language or 3rd party classes if (nonGtwmClassesLogged < 15) { errorMessage += " " + stackTraceElement.toString() + "\r\n"; } } } return errorMessage; }
From source file:Main.java
public Main() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(400, 300);//from w w w .ja va 2s.c o m Exception ex = new Exception(); AttributeSet attr = null; StyledDocument doc = text.getStyledDocument(); for (StackTraceElement trace : ex.getStackTrace()) { try { doc.insertString(doc.getLength(), trace.toString() + '\n', attr); } catch (BadLocationException ex1) { ex1.printStackTrace(); } } getContentPane().add(new JScrollPane(text)); }
From source file:com.google.dart.server.internal.remote.processor.ResultProcessor.java
RequestError generateRequestError(Exception exception) { String message = exception.getMessage(); String stackTrace = null;//from w w w .j a v a2 s . c om if (exception.getStackTrace() != null) { stackTrace = ExceptionUtils.getStackTrace(exception); } return new RequestError(ExtendedRequestErrorCode.INVALID_SERVER_RESPONSE, message != null ? message : "", stackTrace); }
From source file:org.apache.openejb.server.cli.StreamManager.java
public void writeErr(final Exception e) { if (e.getStackTrace() == null) { write(serr, e.getMessage());/*from ww w . j a v a2s . c o m*/ } else { final StringBuilder error = new StringBuilder(); error.append(e.getMessage()).append(lineSep); for (final StackTraceElement elt : e.getStackTrace()) { error.append(" ").append(elt.toString()).append(lineSep); } write(serr, error.toString()); } }
From source file:com.comcast.video.dawg.controller.park.PopulateControllerTest.java
@Test public void testPopulate() { HouseRestController houseController = EasyMock.createMock(HouseRestController.class); EasyMock.expect(houseController.populate((String) EasyMock.anyObject(), (Boolean) EasyMock.anyObject())) .andReturn(1);/*w w w . j a v a 2s. c o m*/ PopulateController controller = new PopulateController(); ParkService mockParkService = new MockParkService(); mockParkService.saveToken(new ChimpsToken("")); EasyMock.replay(houseController); ReflectionTestUtils.setField(controller, "parkService", mockParkService); ReflectionTestUtils.setField(controller, "houseController", houseController); try { controller.populate(); } catch (Exception e) { Assert.fail(e.getStackTrace().toString()); } }