惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
V
Visual Studio Blog
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
IT之家
IT之家
博客园_首页
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - Franky
雷峰网
雷峰网
罗磊的独立博客
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
The Cloudflare Blog
T
Tailwind CSS Blog
B
Blog RSS Feed
H
Help Net Security
T
The Blog of Author Tim Ferriss
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
C
CERT Recently Published Vulnerability Notes
博客园 - 三生石上(FineUI控件)
P
Palo Alto Networks Blog
I
Intezer
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
S
Securelist
J
Java Code Geeks
V
V2EX
Y
Y Combinator Blog
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog
Forbes - Security
Forbes - Security
Google Online Security Blog
Google Online Security Blog
Help Net Security
Help Net Security
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
SecWiki News
SecWiki News
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic

博客园 - ymz

【转】[翻译]Visual Studio2008的新功能:代码度量 【转】也谈c#调用C++的DLL找不到入口点 Develope express学习 【摘】异源数据转换与FDO数据访问 线程同步 线程异步 【转】ArcEngine中创建自定义工具 【转贴】利用 Javascript 获取 URL 参数(适合IE、FF) - ymz 【转】HTML标签大全 MapGuide常见错误解决方法 集合类及泛型 一个网站系统的经验 frameset学习摘录 【转】如何使用.NET配置文件by沐枫小筑 【转】Notes on the Eclipse Plug-in Architecture 【转】理解session机制 困扰了一天的字符集转换问题 【转】Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it 【转】获取GridView单元格值的通用函数
C#异常的一些使用原则
ymz · 2010-02-25 · via 博客园 - ymz
  • 始终按从最特定到最不特定的顺序对 Catch 块中的异常排序。
  • 使用编程方法检查错误(判断语句if等)比异常的效率更高。
  • 抛出异常的使用情况:对非常常见的错误情况返回空,不常见的情况才抛出异常;若属性集或方法调用不适当,则引发 InvalidOperationException;如果传递无效的参数,则引发 ArgumentException 或从 ArgumentException 派生的类;
  • 类的设计应使在正常使用中从不引发异常。
  • 当创建用户定义的异常时,必须确保异常的元数据对远程执行的代码可用,包括当异常跨应用程序域发生时。否则可能会引发FileNotFoundException。
  • 创建自定义异常时至少使用的三个公共构造函数:Exception(),Exception(string message):base(message),Exception(string message, Exception inner):base(message, inner)
  • 堆栈跟踪从引发异常的语句开始,到捕捉异常的 Catch 语句结束。当决定在何处放置 Throw 语句时需考虑这一点。
  • 若需要多处使用Throw的情况,且Throw的语句类似,可以通过一个返回值为异常类的函数实现。
  • 抛出异常时,若返回值未赋值也不会报错。

posted on 2010-02-25 17:33  ymz  阅读(481)  评论()    收藏  举报