Thread Exception Handling (Excerpt from WWW)
来源:互联网 发布:枕头哪个牌子最好 知乎 编辑:程序博客网 时间:2024/06/05 07:26
Exception Handling
Any try/catch/finally blocks in scope when a thread is created are of no relevance once the thread starts executing. Consider
the following program:
public static void Main() {
try {
new Thread (Go).Start();
}
catch (Exception ex) {
// We'll never get here!
Console.WriteLine ("Exception!");
}
static void Go() { throw null; }
}
The try/catch statement in this example is effectively useless, and the newly created thread will be encumbered with an
unhandled NullReferenceException. This behavior makes sense when you consider a thread has an independent execution path. The
remedy is for thread entry methods to have their own exception handlers:
public static void Main() {
new Thread (Go).Start();
}
static void Go() {
try {
...
throw null; // this exception will get caught below
...
}
catch (Exception ex) {
Typically log the exception, and/or signal another thread
that we've come unstuck
...
}
From .NET 2.0 onwards, an unhandled exception on any thread shuts down the whole application, meaning ignoring the exception
is generally not an option. Hence a try/catch block is required in every thread entry method – at least in production
applications – in order to avoid unwanted application shutdown in case of an unhandled exception.
- Thread Exception Handling (Excerpt from WWW)
- quine (T-SQL Version, Excerpt From WWW)
- quine in HTML (Excerpt From WWW)
- http://www.georgerrmartin.com/excerpt-from-the-winds-of-winter/
- Exception handling
- Exception Handling
- Exception Handling
- Exception Handling
- Exception Handling
- Exception Handling
- exception handling
- Exception Handling
- C# Exception Handling
- Exception Handling Rules
- Structured Exception Handling(SEH)
- Exception Handling in C#
- Vectored Exception Handling
- EAI Exception Handling Patterns
- StoneAge Dict 技术方案的可行性[2]
- About BackgroundWorker
- C# read xml from a string and performance test
- Get cruuent function name, file... (even in release build)
- 各版本的 VS2008
- Thread Exception Handling (Excerpt from WWW)
- 谈Intranet、Internet诸词的译名:内联网、互联网、因特网等等
- javascript继承基础
- ACE环境配置
- 无法读取System Overview 日志或警报解决方法
- 程序员研发、IT商场、青春文学、职场经典《无以言退》华为背景
- 写给程序员的诗歌《鹅》
- Oracle 用户管理与安全 实操
- 拷贝构造函数