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

以下实例演示了使用异常类的 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)

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-04
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2021-08-17
相关资源
相似解决方案