first_exception.java

来自「java2参考大全上的例子的源码和自己的理解.」· Java 代码 · 共 38 行

JAVA
38
字号
package first_exception;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

class first_exception {
  public static void main(String args[]) {
    char c;
    int a, b = 0;
    int[] array = new int[7];
    String s = "Hello";
    try {
      a = 1 / b;
    }
    catch (ArithmeticException ae) {
      System.out.println("Catch " +ae);
    }
    try {
      array[8] = 0;
    }
    catch (ArrayIndexOutOfBoundsException ai) {
      System.out.println("Catch " +ai);
    }
    try {
      c = s.charAt(8);
    }
    catch (StringIndexOutOfBoundsException se) {
      System.out.println("Catch " +se);
    }
  }
}

⌨️ 快捷键说明

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