Java获取 Exception异常详细信息

public static String getExceptionAllInfo(Exception ex) {
        ByteArrayOutputStream out = null;
        PrintStream pout = null;
        String ret = "";
        try {
        	out = new ByteArrayOutputStream();
        	pout = new PrintStream(out);
        	ex.printStackTrace(pout);
	        ret = new String(out.toByteArray());
	        out.close();
        }catch(Exception e){
        	return ex.getMessage();
        }finally{
        	if(pout!=null){
        		pout.close();
        	}
        }
        return ret;
}

猜你喜欢

转载自blog.csdn.net/zengmingen/article/details/106416143