为什么SecurityException是一个运行时异常? | 您所在的位置:网站首页 › ioexception有哪些 › 为什么SecurityException是一个运行时异常? |
SecurityException是RuntimeException的子类,所以在运行过程中所抛出的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 * checkPropertiesAccess 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: ... } |
CopyRight 2018-2019 实验室设备网 版权所有 |