My blog has moved! Redirecting...

You should be automatically redirected. If not, visit and update your bookmarks.

09 September 2008

Unhandled Exceptions Crash .NET Threads

A little something I learned at DSM today. It appears if any thread in .NET crashes (lets a thrown exception fly through the top stack level), the process crashes. I refused to believe at first, but testing on .NET 2.0 showed it to be true:

(I should really switch to another blog platform, I didn't find a decent way to write code in Blogspot).

class ThreadCrashTest
static void Main()
new Thread(Foo).Start();
for (int i = 0; i < 10; ++i)

private static void Foo()
throw new Exception("");

According to Yan, the behavior on .NET 3 is to crash the AppDomain instead of the entire process.


orip said...

For code in posts, a quick fix is to use '<pre>' html blocks.

For nice syntax highlighting check out SyntaxHighlighter (usage is here)

ripper234 said...

Thanks for the tip, through I am right in the middle of a move (hush hush) to Wordpress. Will use a proper plugin there.