zoukankan      html  css  js  c++  java
  • 关于打印日志几个方法的列举

    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.StringWriter;

    import org.junit.Test;

    public class ExceTest {
        @Test
        public static void main(String[] args){
            try {
    //            throw new Exception("发生异常");
                Integer.valueOf("a");
            } catch (Exception e) {
                //只会获得具体的异常名称. 比如说NullPoint 空指针,就告诉你说是空指针...
                System.out.println("e.getMessage 异常信息:"+e.getMessage());
                
                //来提供一个针对地区方言的错误信息
                System.out.println("e.getLocalizedMessage 异常信息:"+e.getLocalizedMessage());
                
                //e.getCause()有可能返回null
                System.out.println("e.getCause 异常信息:"+e.getCause().getMessage());
                
                StringWriter sw = new StringWriter();  
                PrintWriter pw = new PrintWriter(sw);  
                e.printStackTrace(pw);
                System.out.println(sw.toString());
                
                try {
                    ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream();
                    //会打出详细异常,异常名称,出错位置,便于调试用,printStackTrace 有三个重载的方法
                    e.printStackTrace(new java.io.PrintWriter(buf, true));
                    String expMessage = buf.toString();
                    System.out.println("e.printStackTrace 异常信息: "+expMessage);
                    buf.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }

  • 相关阅读:
    模仿.Net ThreadPool的线程池控件
    ThreadPool for Delphi
    Thread Pool Engine, and Work-Stealing scheduling algorithm
    Delphi ThreadPool 线程池(Delphi2009以上版本适用)
    Object Pascal对象模型中构造函数之研究
    TExternalThread TThread -- Delphi -- Cannot terminate an externally created thread ?
    Trapping Messages Sent to an Application
    Correct thread terminate and destroy
    Delphi thread exception mechanism
    VCL -- Understanding the Message-Handling System
  • 原文地址:https://www.cnblogs.com/robertsun/p/5129904.html
Copyright © 2011-2022 走看看