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

📄 demonexception.java

📁 压缩包内是近180多个针对Java初学者编写的简单实例
💻 JAVA
字号:
//使用自定义异常类。
class MyException extends Exception {
  private int attribute;
	
  MyException(int i) {
    attribute = i;
  }

  public String toString() {
    return "MyException[" + attribute + "]";
  }
}

class DemonException {
  static void compare(int a) throws MyException {
    System.out.println("Called compare(" + a + ")");
    if(a > 5)
      throw new MyException(a);
    System.out.println("Normal exit");
  }

  public static void main(String args[]) {
    try {
      compare(3);
      compare(15);
    } 
    catch (MyException e) {
      System.out.println("Caught " + e);
    }
  }
}

⌨️ 快捷键说明

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