Java Exception to String getExceptionMsg(Exception ex)

Here you can find the source of getExceptionMsg(Exception ex)

Description

Get Exception msg.

License

Apache License

Declaration

public static String getExceptionMsg(Exception ex) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    /**//from  w  w  w  .j a  va 2 s .co  m
     * Get Exception msg.
     * */
    public static String getExceptionMsg(Exception ex) {
        StringBuilder sb = new StringBuilder();
        if (ex != null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            ex.printStackTrace(pw);
            sb.append(sw.toString());
        }
        return sb.toString();
    }
}

Related

  1. getException(Exception e)
  2. getExceptionDetails(Exception e)
  3. getExceptionMessage(Exception e)
  4. getExceptionMessage(Exception ex)
  5. getExceptionMessage(Exception ex)
  6. getExceptionName(IOException ex)
  7. getExceptionStackTrace(Exception exception)
  8. getExceptionStackTraceAsString(final Exception exception)