易百教程

143、以下 Java 程序的输出是什么?

public class Main {

    public static void main(String[] args) {
        try {
            throw 90;
        } catch (int e) {
            System.out.println("Caught the exception " + e);
        }
    }
}

运行结果:

Main.java:6: error: incompatible types: int cannot be converted to Throwable
            throw 90; 
            ^
Main.java:8: error: unexpected type
        catch(int e){
              ^
  required: class
  found:    int
2 errors

解释:在 Java 中,可抛出对象只能被抛出。如果尝试抛出一个整数对象,编译器将显示错误,因为不能从代码块中抛出基本数据类型。