加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在C#中抛出保留的异常会出现什么问题?

发布时间:2020-12-15 07:59:06 所属栏目:百科 来源:网络整理
导读:如果在代码中抛出System.IndexOutOfRangeException,则FxCop会违反规则CA2201( see reference).根据文档,System_IndexOutOfRangeException是“保留的,应该只由公共语言运行库抛出”的基本原理. 但是,如果抛出System.IndexOutOfRangeException,实际上会出现什
如果在代码中抛出System.IndexOutOfRangeException,则FxCop会违反规则CA2201( see reference).根据文档,System_IndexOutOfRangeException是“保留的,应该只由公共语言运行库抛出”的基本原理.

但是,如果抛出System.IndexOutOfRangeException,实际上会出现什么问题?

解决方法

没有.

从技术角度来看,抛出这个异常是完全可以的.如果你这样做,什么都不会破坏.

但请记住,只有在第一个地方遇到System.IndexOutOfRangeException时才应抛出System.IndexOutOfRangeException,因为否则此异常将不合适,因为它非常清楚地定义了此异常类型的用途. MSDN states for the System.IndexOutOfRangeException:

The exception that is thrown when an attempt is made to access an element of an array with an index that is outside the bounds of the array. This class cannot be inherited.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读