Difference between IllegalAccessError and IllegalAccessException

后端 未结 3 1933
遇见更好的自我
遇见更好的自我 2021-02-04 15:14

Consider this pair of Throwable:

IllegalAccessExceptionextends Exception

Thrown when an application tries to reflectively cr

3条回答
  •  春和景丽
    2021-02-04 15:50

    There are several pairs of Exception/Error in java.lang, and all of the following deal with reflective vs. direct usage:

    IllegalAccessException / IllegalAccessError
    InstantiationException / InstantiationError
    ClassNotFoundException / NoClassDefFoundError
    NoSuchFieldException / NoSuchFieldError
    NoSuchMethodException / NoSuchMethodError
    

    Other examples are:

    java.awt.AWTException / java.awt.AWTError
    java.io.IOException / java.io.IOError
    

    Until now, I didn't know these two errors existed, and they are not referenced from other classes in the Javadoc (1.6). So I don't know if and when they are thrown.

提交回复
热议问题