Java 实例 - 获取异常的堆栈信息

Java 教程 · 2019-02-11 10:44:00

以下实例演示了使用异常类的 printStack() 方法来获取堆栈信息:

Main.java 文件

public class Main{ public static void main (String args[]){ int array[]={20,20,40}; int num1=15,num2=10; int result=10; try{ result = num1/num2; System.out.println("The result is" +result); for(int i =5; i>=0; i--) { System.out.println("The value of array is" +array[i]); } } catch (Exception e) { e.printStackTrace(); } } }

以上代码运行输出结果为:

The result is1
java.lang.ArrayIndexOutOfBoundsException: 5
        at testapp.Main.main(Main.java:28)

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Algorithms to Live By

Algorithms to Live By

Brian Christian、Tom Griffiths / Henry Holt and Co. / 2016-4-19 / USD 30.00

A fascinating exploration of how insights from computer algorithms can be applied to our everyday lives, helping to solve common decision-making problems and illuminate the workings of the human mind ......一起来看看 《Algorithms to Live By》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具