运行 ❯
获取您
自己的Java
服务器
×
更改方向
更改主题,深色/浅色
前往 Spaces
public class Main { static void checkAge(int age) throws ArithmeticException { if (age < 18) { throw new ArithmeticException("Access denied - You must be at least 18 years old."); } else { System.out.println("Access granted - You are old enough!"); } } public static void main(String[] args) { checkAge(15); } }
Exception in thread "main" java.lang.ArithmeticException: Access denied - You must be at least 18 years old.
在 MyClass.checkAge(MyClass.java:4)
在 MyClass.main(MyClass.java:12)