Java Utililty Methods Exception Format

List of utility methods to do Exception Format

  1. HOME
  2. Java
  3. E
  4. Exception Format

Description

The list of methods to do Exception Format are organized into topic(s).

Method

String fmtError(Exception e)
fmt Error
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
 e.printStackTrace(pw);
 pw.flush();
} finally {
 pw.close();
sw.flush();
return e.getMessage() + "\n" + sw.toString();
String formatException(final Exception e)
Formats the given exception in a multiline error message with all causes.
final StringBuilder sb = new StringBuilder();
Throwable t = e;
while (t != null) {
 sb.append(t.getMessage()).append("\n");
 t = t.getCause();
return sb.toString();
String formatException(Throwable ex)

Returns a formatted string in the java style exception format.

StringBuilder sb = new StringBuilder();
sb.append(ex.getMessage());
sb.append("\n");
StackTraceElement[] trace = ex.getStackTrace();
for (int i = 0; i < trace.length; i++) {
 sb.append("\t");
 sb.append(trace[i]);
 sb.append("\n");
...
String formatException(Throwable exception)
Formatea una excepcion y las excepciones padre.
StringBuilder buffer = new StringBuilder();
formatException(exception, buffer);
return buffer.toString();
String formatException(Throwable th)
Format the information from a Throwable as string, retaining the type and its message.
return "[" + th.getClass().getSimpleName() + "]: " + th.getMessage();
String formatExceptionMsg(String msg)
formats a message that will be displayed in a dialog, so it's not longer than 80 symbols in each line
msg = msg.replace("\n", "");
if (msg.length() > 80) {
 String result = "";
 for (int i = 0; i < msg.length(); i = i + 80) {
 int end = i + 80;
 if (msg.length() < i + 80)
 end = msg.length();
 String s = msg.substring(i, end);
...
String formatJavaException(Exception e)
format Java Exception
return e.getClass().getSimpleName() + " - " + e.getMessage();
String formatLogMessage(long id, Throwable exception)
format Log Message
return String.format("Error handling a request: %016x", id);
String formatMessage(Exception e)
format Message
String msg = e.getMessage();
Throwable cause = e.getCause();
if (cause != null)
 msg = msg + "\nCause: " + cause.getMessage();
return msg;
String formatStackTrace(Exception error)
format Stack Trace
final StringBuffer br = new StringBuffer();
StackTraceElement[] elem = error.getStackTrace();
for (int i = 0; i < elem.length; i++)
 br.append(elem[i].toString() + "\n");
return br.toString();


AltStyle によって変換されたページ (->オリジナル) /