2012年3月28日 星期三

[Java] Log Java Exception

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

public class Main {  
    public static void main(String[] args) {  
        try {  
            int dividedByZero = 1/0;  
        } catch (Exception e) {  
            StringWriter traceWriter = new StringWriter();  
            PrintWriter printWriter = new PrintWriter(traceWriter, false);  
            e.printStackTrace(printWriter);  
            printWriter.close();          
            System.out.println(traceWriter.getBuffer().toString());  
        }  
    }  
} 

沒有留言:

張貼留言