JAVA获取catch中的异常信息

package com.zys.test;

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


public class UnicodeTest {
    public static void main(String[] args) {
        String str = null;
        try
        {
            System.out.println(str.toString());
        }catch(Exception e)
        {
            StringWriter stringWriter= new StringWriter();
            PrintWriter writer= new PrintWriter(stringWriter);
            e.printStackTrace(writer);
            StringBuffer buffer= stringWriter.getBuffer();
            System.out.println(buffer.toString());
        }
    }
    
    private static void unicodeTransformation(String str)
    {
        char [] obj = str.toCharArray();
        
        for(int i=0;i<obj.length;i++)
        {
            System.out.print("\\u"+Integer.toHexString(obj[i]).toUpperCase());
        }
    }
}

 

posted @ 2015-05-11 16:16  精神领袖  阅读(3416)  评论(0编辑  收藏  举报