为什么SecurityException是一个运行时异常?

IOException有什么必要的原因是检查型的异常,而SecurityException是运行时异常呢
关注者
3
被浏览
12,267
登录后你可以
不限量看优质回答私信答主深度交流精彩内容一键收藏

SecurityExceptionRuntimeException的子类,所以在运行过程中所抛出的SecurityException都应是预期之外的,相关的程序若使用不当可能会存在某些危险的操作从而引发安全问题。

比如这个:

package sun.misc;
/**
 * A collection of methods for performing low-level, unsafe operations.
 * Although the class and all methods are public, use of this class is
 * limited because only trusted code can obtain instances of it.
 *
 * @author John R. Rose
 * @see #getUnsafe
 */
public final class Unsafe {
    private static native void registerNatives();
    static {
        registerNatives();
        sun.reflect.Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
    }
    private Unsafe() {}
    private static final Unsafe theUnsafe = new Unsafe();
    /**
     * Provides the caller with the capability of performing unsafe
     * operations.
     *
     * @exception  SecurityException  if a security manager exists and its
     *             <code>checkPropertiesAccess</code> method doesn't allow
     *             access to the system properties.
     */
    @CallerSensitive
    public static Unsafe getUnsafe() {
        Class<?> caller = Reflection.getCallerClass();
        if (!VM.isSystemDomainLoader(caller.getClassLoader()))
            throw new SecurityException("Unsafe");
        return theUnsafe;
    }
    // TODO: ...
}