While e.printStackTrace(); always writes onto stderr, there are also ways to get the full message of an exception, including all nested exceptions.
public static String getExceptionMessage(Throwable e) { Throwable cause = e; String sRet=""; do { sRet += "["+cause.getClass().getName() +"] "; sRet += cause.getMessage()+"\n"; cause = cause.getCause(); } while (cause!=null); return sRet; }
public static String getExceptionStackTrace(Throwable e) { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(out); e.printStackTrace(ps); ps.flush(); return out.toString(); }
No comments:
Post a Comment