UnauthorizedAccessException VS SecurityException异常 [英] UnauthorizedAccessException vs SecurityException

查看:240
本文介绍了UnauthorizedAccessException VS SecurityException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MSDN构造一个FileStream说,它可能会抛出要么是UnauthorizedAccessException或一个SecurityException。下面是MSDN说,有关这些异常。

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.

<一个href="http://msdn.microsoft.com/en-us/library/system.unauthorizedaccessexception.aspx">UnauthorizedAccessException: 时引发的异常时,操作系统拒绝,因为一个I / O错误或安全错误的特定类型的访问。

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.

<一个href="http://msdn.microsoft.com/en-us/library/system.security.securityexception.aspx">SecurityException: 所不同的是检测到安全错误时抛出。

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 时出现权限错误访问磁盘上的文件抛出。这是操作系统级别的错误,如一个普通用户试图覆盖操作系统文件(比如kernel32.dll)。

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异常被抛出。例如,如果你正在运行的低访问ClickOnce应用程序,并尝试读取/写入由CLR安全设置的过程中禁止的文件系统中的位置。

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.

这篇关于UnauthorizedAccessException VS SecurityException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆