List of utility methods to do Exception to String
String | exceptionToString(Throwable e) exception To String StringBuilder sb = new StringBuilder(128); StackTraceElement elements[] = e.getStackTrace(); sb.append(e.toString()); sb.append("\n"); for (int n = 0; n < elements.length; ++n) { sb.append(" at "); sb.append(elements[n].getClassName()); sb.append("."); ... |
String | exceptionToString(Throwable ex) exception To String return exceptionToString(ex, ""); |
String | exceptionToString(Throwable exception) Converts given exception to String, including file name and line number StringBuffer str = new StringBuffer(); str.append(exception.toString()); if (exception.getStackTrace().length > 0) { StackTraceElement location = exception.getStackTrace()[0]; str.append(" ("); str.append(location.getFileName()); str.append(":"); str.append(location.getLineNumber()); ... |
String | exceptionTypeAndMsg(Exception e) Displays both the exception class and the message. return e.getClass() + " : " + e.getMessage(); |
T | exceptionWithCause(T exception, Throwable cause) Throw the exception with the specified cause. exception.initCause(cause);
return exception;
|
String | getErrorMessage(Exception ex) Utility method to send the error back to UI return "Error:" + ex.toString(); |
String | getErrorMessage(Exception ex) get Error Message StringWriter stringWriter = new StringWriter(); ex.printStackTrace(new PrintWriter(stringWriter)); String returnStr = new String(stringWriter.getBuffer()); stringWriter.flush(); try { stringWriter.close(); } catch (IOException e) { e.printStackTrace(); ... |
String | getErrorMessage(Process process) get Error Message if (process == null) { return ""; BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream())); StringBuffer sb = new StringBuffer(); String str = br.readLine(); while (str != null) { str = br.readLine(); ... |
String | getException(Exception e) get Exception StringWriter w = new StringWriter(); e.printStackTrace(new PrintWriter(w)); return w.toString(); |
String | getExceptionDetails(Exception e) Gets the details of this exception. if (e == null) return ""; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); e.printStackTrace(ps); return "Exception thrown: " + e.getClass().getName() + "\n" + e.getMessage() + "\n" + new String(baos.toByteArray()); |