Get more information for exception
My own environment for running tests: Windows XP, eclipse3.5.1, jdk1.6
The following three methods are the details of getting the exception, and perhaps the exception details are returned as strings, preserving the style of the stack load
Method One:
public static String Getexceptionallinformation (Exception ex) {
String sOut = "";
Stacktraceelement[] trace = Ex.getstacktrace ();
for (Stacktraceelement s:trace) {
SOut + = "\tat" + S + "\ r \ n";
}
return sOut;
}
Method Two:
public static String getexceptionallinformation_01 (Exception ex) {
Bytearrayoutputstream out = new Bytearrayoutputstream ();
PrintStream pout = new PrintStream (out);
Ex.printstacktrace (pout);
string ret = new string (Out.tobytearray ());
Pout.close ();
try {
Out.close ();
catch (Exception e) {
}
return ret;
}
Method Three:
private static String tostring_02 (Throwable e) {
StringWriter SW = new StringWriter ();
PrintWriter pw = new PrintWriter (SW, True);
E.printstacktrace (PW);
Pw.flush ();
Sw.flush ();
return sw.tostring ();
}