Java Exception to String getExceptionMessage(Exception e)

Here you can find the source of getExceptionMessage(Exception e)

Description

Retrieve exception stack message

License

Open Source License

Parameter

Parameter Description
e Exception e

Return

excpetion message

Declaration

public static String getExceptionMessage(Exception e) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

public class Main {
    /**//from w w w.  jav  a2 s. co  m
     * Retrieve exception stack message
     * 
     * @param e
     *            Exception e
     * @return excpetion message
     */
    public static String getExceptionMessage(Exception e) {
        final StringBuilder sb = new StringBuilder();
        e.printStackTrace(new PrintStream(new OutputStream() {
            @Override
            public void write(int b) throws IOException {
                sb.append((char) b);
            }
        }));
        return sb.toString();
    }
}

Related

  1. getErrorMessage(Exception ex)
  2. getErrorMessage(Exception ex)
  3. getErrorMessage(Process process)
  4. getException(Exception e)
  5. getExceptionDetails(Exception e)
  6. getExceptionMessage(Exception ex)
  7. getExceptionMessage(Exception ex)
  8. getExceptionMsg(Exception ex)
  9. getExceptionName(IOException ex)