微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如果在代码中抛出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.

原文地址:https://www.jb51.cc/csharp/100199.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐