TestException
来源:互联网 发布:怎么重置mac 编辑:程序博客网 时间:2024/06/05 06:03
public class TestException {
public static void main(String[] args) {
try {
System.out.println(sum(new int[] {1, 2, 3, 4, 5}));
}
catch(Exception ex) {
ex.printStackTrace();
System.out.println("\n" + ex.getMessage());
System.out.println(ex.toString());
StackTraceElement[] element = ex.getStackTrace();
System.out.println("Trace Info Obtained from getStackTrace");
for(int i = 0; i < element.length; i++) {
System.out.print("Method " + element[i].getMethodName());
System.out.print(" (" + element[i].getClassName() + ": ");
System.out.println(element[i].getLineNumber() + ")");
}
}
}
private static int sum(int[] list) {
int result = 0;
for(int i = 0; i <=list.length; i++)
result += list[i];
return result;
}
}
java.lang.ArrayIndexOutOfBoundsException: 5
at TestException.sum(TestException.java:24)
at TestException.main(TestException.java:4)
5
java.lang.ArrayIndexOutOfBoundsException: 5
Trace Info Obtained from getStackTrace
Method sum (TestException: 24)
Method main (TestException: 4)
public static void main(String[] args) {
try {
System.out.println(sum(new int[] {1, 2, 3, 4, 5}));
}
catch(Exception ex) {
ex.printStackTrace();
System.out.println("\n" + ex.getMessage());
System.out.println(ex.toString());
StackTraceElement[] element = ex.getStackTrace();
System.out.println("Trace Info Obtained from getStackTrace");
for(int i = 0; i < element.length; i++) {
System.out.print("Method " + element[i].getMethodName());
System.out.print(" (" + element[i].getClassName() + ": ");
System.out.println(element[i].getLineNumber() + ")");
}
}
}
private static int sum(int[] list) {
int result = 0;
for(int i = 0; i <=list.length; i++)
result += list[i];
return result;
}
}
java.lang.ArrayIndexOutOfBoundsException: 5
at TestException.sum(TestException.java:24)
at TestException.main(TestException.java:4)
5
java.lang.ArrayIndexOutOfBoundsException: 5
Trace Info Obtained from getStackTrace
Method sum (TestException: 24)
Method main (TestException: 4)
0 0
- TestException
- SpringAOP嵌套调用的解决办法
- 关于SafeMove White Paper功能
- 一个常见的优先级问题
- golang sync mutex 互斥锁
- 5.7
- TestException
- Generating Your Development Certificate
- printf格式控制符的完整格式
- 线程与Handler(1)
- 面试中Spring IOC AOP的理解
- mac安装配置JDK1.7
- iOS Crash Log 理解2
- <aop:aspectj-autoproxy/>
- Android模拟位置出错IllegalArgumentException: Incomplete location object, missing timestamp or accuracy?