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

推荐订阅源

S
Securelist
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
博客园 - 聂微东
博客园 - 【当耐特】
小众软件
小众软件
V
V2EX
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
The Hacker News
The Hacker News
AI
AI
O
OpenAI News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Threat Research - Cisco Blogs
Jina AI
Jina AI
博客园_首页
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
IT之家
IT之家
V
Vulnerabilities – Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google Online Security Blog
Google Online Security Blog
G
GRAHAM CLULEY
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hacker News: Ask HN
Hacker News: Ask HN
P
Palo Alto Networks Blog
S
SegmentFault 最新的问题
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News and Events Feed by Topic
V
Visual Studio Blog
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志

博客园 - 赤脚小子

Workflow WF Reference Links for 2009-03-20 Workflow WF Reference Links for 2009-03-06 Workflow WF Reference Links for 2009-02-20 Workflow WF Reference Links for 2009-02-13 Workflow WF Reference Links for 2009-02-06 Workflow WF Reference Links for 2009-02-01 Workflow WF Reference Links for 2009-01-16 Workflow WF Reference Links for 2009-01-09 Workflow WF Reference Links for 2008-12-30 WF书籍导读(完整版) WF书籍推荐 Unity(七):使用场景Ⅲ:用于依赖注入(下) Unity系列目录 Unity(六):使用场景Ⅲ:用于依赖注入(上) Unity(五):使用场景Ⅱ:用于单例模式 Unity(四):使用场景Ⅰ:建立类型映射 Unity(三):快速入门 Unity(二):Unity是什么? Unity(一):从ObjectBuilder说起
Exception Management in .NET阅读笔记
赤脚小子 · 2008-02-15 · via 博客园 - 赤脚小子

前两天看到Haissam推荐的一片文章——Exception Management in .NET.

确实是篇好文章,虽然有些年头了,但是仍颇有价值。仔细一看,原来是P&P出的一个Guide。

以下是一些我觉得有用的要点:

异常处理流程

  • exception handling process.

Figure 2. Exception handling process

  • Processing of unhandled exceptions, see Figure 3.

Figure 3. Processing of unhandled exceptions

异常检测

You should only catch exceptions when you need to specifically perform any of the following actions:

  • Gather information for logging

  • Add any relevant information to the exception

  • Execute cleanup code

  • Attempt to recover

异常传播
There are three main ways to propagate exceptions:

  • Let the exception propagate automatically:With this approach, you do nothing and deliberately ignore the exception.

  • Catch and rethrow the exception:With this approach, you catch and react to the exception, and clean up or perform any other required processing within the scope of the current method. If you cannot recover from the exception, you rethrow the same exception to your caller.

catch(TypeAException e)

{

// Code to do any processing needed.

// Rethrow the exception

throw;

}

  • Catch, wrap, and throw the wrapped exception:If you cannot recover, wrap the exception in a new exception, and throw the new exception back to the caller. The InnerException property of the Exception class explicitly allows you to preserve a previously caught exception. This allows the original exception to be wrapped as an inner exception inside a new and more relevant outer exception.

catch(TypeBException e)

{

// Code to do any processing needed.

// Wrap the current exception in a more relevant

// outer exception and rethrow the new exception.

throw(new TypeCException(strMessage, e));

}

When to use inner exception
You should wrap an exception only when wrapping an exception can provide a more relevant exception to the caller.

管理未处理异常

When an unhandled exception propagates to the last point or boundary at which your application can handle the exception before returning to the user, your application can no longer recover from the exception. At this point, it must gather information, log information, send any notifications, perform any cleanup, and do any other processing needed before managing the communication of the exception condition

to the user.

收集信息

What is the required information, just see table 2:


ps:文中关于Exception Hierarchies的部分有些过时了,现在的异常体系并没有严格遵守这种分类规则。