⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tryexceptiontrace.java

📁 Java 入门书的源码
💻 JAVA
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

/* Shows the use of the printStackTrace method
 * to obtain the sequence of method calls that 
 * culminated in the throwing of the array index 
 * out of bounds exception.
 */

import iopack.Io;
public class TryExceptionTrace{
  public static int getAndSetValue() {
    int [] anArray = {5,6,7};
    int index = Io.readInt("Enter an index from 0 to 2"); 
    return anArray[index];
  }
  public static void main(String [] args) {  
    int value;
    try {
      value = getAndSetValue();
      System.out.println("Execution does not get here if index is bad");
    }catch (ArrayIndexOutOfBoundsException e) {
       e.printStackTrace();
    }
    System.out.println("This is the end of the program");
    Io.readString("Press any key to exit");   // Added for IDE use
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -