try{ .................... } catch(Exception e){ //定义一个流 ByteArrayOutputStream ostr = new ByteArrayOutputStream(); //把错误堆栈储存到流中 e.printStackTrace(new PrintStream(ostr)); //打印.... out.println(ostr.toString()); }