1. import java.io.PrintWriter;
    2. import java.io.StringWriter;
    3. public class ExceptionUtils {
    4. /**
    5. * 获取异常详细信息
    6. */
    7. public static String getExceptionMsg(Exception e){
    8. String msg = null;
    9. try {
    10. StringWriter sw = new StringWriter();
    11. PrintWriter pw = new PrintWriter(sw,true);
    12. e.printStackTrace(pw);
    13. pw.flush();
    14. sw.flush();
    15. msg = sw.toString();
    16. pw.close();
    17. sw.close();
    18. }catch (Exception error){
    19. error.printStackTrace();
    20. }
    21. return msg;
    22. }
    23. }