zoukankan      html  css  js  c++  java
  • 异常信息重定向及相关处理办法

        public static String outputThrowable(Throwable t) throws FileNotFoundException{
            for (StackTraceElement ste:t.getStackTrace()) {
                System.out.println(ste.getMethodName());
            }
            t.printStackTrace(System.err);
            t.printStackTrace(System.out);
            t.printStackTrace(new PrintStream("exception.txt"));//redirect to file
            
            StringWriter sw=new StringWriter();
            PrintWriter pw=new PrintWriter(sw);
            
            try {
                t.printStackTrace(pw);//redirect to file
            } catch (Exception e) {
                e.printStackTrace();
            }finally{
                pw.close();
            }
            
            return sw.toString();
            
        }

    Output:

    main
    java.lang.ArithmeticException: / by zero
        at exception.TestException.main(TestException.java:11)
    java.lang.ArithmeticException: / by zero
        at exception.TestException.main(TestException.java:11)
    java.lang.ArithmeticException: / by zero
        at exception.TestException.main(TestException.java:11)
    java.lang.ArithmeticException: / by zero
        at exception.TestException.main(TestException.java:11)




  • 相关阅读:
    Electio Time poj
    排列的字典序问题
    poj 2365
    编程中的命名设计那点事(转)
    编程命名中的7+1个提示(转)
    poj 1664 放苹果——递归
    再论字典序
    poj 3618
    sort用法
    poj 1088
  • 原文地址:https://www.cnblogs.com/softidea/p/4266560.html
Copyright © 2011-2022 走看看