StringWriter sw = null;
PrintWriter pw = null;
try {
sw = new StringWriter();
pw = new PrintWriter(sw);
e.printStackTrace(pw);//将出错的栈信息输出到printWriter中
pw.flush();
sw.flush();
String message = sw.toString().split("\n")[0].split(":")[1];
JOptionPane.showMessageDialog(null, message,"报错信息",JOptionPane.PLAIN_MESSAGE);
} catch (Exception e2) {
e2.printStackTrace();
} finally {
if (sw != null) {
try {
sw.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
if (pw != null) {
pw.close();
}
}