獲取異常堆棧消息


/**
     * 得到異常信息
     *
     * @param e
     */
    public void errorInfo(Exception e) {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        e.printStackTrace(new PrintWriter(buf, true));
        String expMessage = buf.toString();
        err(expMessage);

    }


//將異常內容輸出到文件
public void logError( Exception ex ) throws IOException
    {
        File log = new File( "log.txt" );
        DataOutputStream dos = new DataOutputStream( new FileOutputStream( log ) );
        ex.printStackTrace( new PrintStream( dos ) );
        dos.flush();
        ..............
    }




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章