UnauthorizedAccessException vs SecurityException

非 Y 不嫁゛ 提交于 2019-12-09 07:46:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/2339251/unauthorizedaccessexception-vs-securityexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!