package com.test1;

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

public class T010 {

/**
* @param args
*/
public static void main(String[] args) {
try {
String[] arr = {"111", "222"};
arr[2] = "fff";
} catch (Exception e) {
String info = getErrorInfoFromException(e);
System.out.println(info);
}
}

public static String getErrorInfoFromException(Exception e) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return "\r\n" + sw.toString() + "\r\n";
} catch (Exception e2) {
return "bad getErrorInfoFromException";
}
}
}

控制台上输出的消息如下所示:
java.lang.ArrayIndexOutOfBoundsException: 2
at com.test1.T010.main(T010.java:14)

相关文章:

  • 2022-01-26
  • 2021-12-24
  • 2021-11-17
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2022-01-05
  • 2021-08-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-12-24
  • 2021-06-30
  • 2021-12-24
相关资源
相似解决方案