Here you can find the source of getStackTraceAsString(String pstrMessage, Exception poException)
Parameter | Description |
---|---|
pstrMessage | custom exception message to prepend to the output |
poException | a parameter |
public static String getStackTraceAsString(String pstrMessage, Exception poException)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.PrintWriter; public class Main { /**/*from w w w. j a v a 2 s.c o m*/ * Writes out the stack trace into a string and returns it * along with the supplied message. * @param pstrMessage custom exception message to prepend to the output * @param poException * @return exception message string with a stack trace */ public static String getStackTraceAsString(String pstrMessage, Exception poException) { String strMessage = ""; // Based on PostgreSQL JDBC driver's PGSQLException. try { ByteArrayOutputStream oByteArrayOutputStream = new ByteArrayOutputStream(); PrintWriter oPrintWriter = new PrintWriter(oByteArrayOutputStream); oPrintWriter.println("Exception: " + poException + "\nStack Trace:\n"); poException.printStackTrace(oPrintWriter); oPrintWriter.println("End of Stack Trace"); strMessage += pstrMessage + " " + oByteArrayOutputStream; oPrintWriter.println(strMessage); oPrintWriter.flush(); oPrintWriter.close(); oByteArrayOutputStream.close(); } catch (Exception e) { strMessage += pstrMessage + " " + poException + "\nError on stack trace generation: " + e; } return strMessage; } }