开发者

UnauthorizedAccessException vs SecurityException

开发者 https://www.devze.com 2022-12-21 03:02 出处:网络
开发者_StackOverflow中文版The MSDN constructor for a FileStream says that it may throw either an UnauthorizedAccessException or a SecurityException. Here\'s what MSDN says about these exceptions.

开发者_StackOverflow中文版The MSDN constructor for a FileStream says that it may throw either an UnauthorizedAccessException or a SecurityException. Here's what MSDN says about these exceptions.

UnauthorizedAccessException: The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.

SecurityException: The exception that is thrown when a security error is detected.

How are these two similar exceptions different? What situations will trigger either of them?


A UnauthorizedAccessException is thrown when there is a permissions error accessing the file on disk. That is an error at the operating system level such as a normal user trying to overwrite an operating system file (like kernel32.dll).

A SecurityException is thrown if there is a security violation at the CLR level. For example if you are running as a low access ClickOnce application and attempt to read / write to a place in the file system forbidden by the CLR security settings in the process.

0

精彩评论

暂无评论...
验证码 换一张
取 消