Monday, January 18, 2016

Convert Exception Details To String Using Java

package com.pritom.kumar;

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

/**
 * Created by pritom on 18/01/2016.
 */
public class ExceptionToString {
    public static String convertExceptionToString(Throwable throwable) {
        try {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            throwable.printStackTrace(pw);
            return sw.toString();
        }
        catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

No comments:

Post a Comment