Welcome to MSDN Blogs Sign in | Join | Help

Watcher of the skies

Channel 9, Astrobiology, Operating Systems, and other unrelated things

Syndication

What do you think of .NET's exception model?

How much you do you really know about the CLR exception model?
Do you know how Windows SEH works? Really?

Please read this article:

http://blogs.msdn.com/cbrumme/archive/2003/10/01/51524.aspx

Now, what do you think of our current managed exception model? What would you like to see in the next version of the CLR with respect to exception handling?

Do you ever write code like this? :

try
{
   Compute();
}
catch( Exception ex )
{
  //boo! (ex happens to be an Access Violation exception)

}

I didn't think so. ;-) But if you do, you should make a point of not ever doing so again as code like the above is very dangerous since it can expose stack-based buffer overrun exploits. You'd be surprised how many times I see the above pattern.

Wouldn't it be nice if C# just supported exception filtering (like VB.NET and MC++) so you could have more granular control over how your application deals with runtime exceptions? If you've found yourself wanting this feature (or any other feature for that matter), just let the C# design people know!

More later.

Published Wednesday, January 28, 2004 5:38 PM by LifeOnTitan

Comments

# re: What do you think of .NET's exception model? @ Wednesday, January 28, 2004 7:31 PM

I have done several presentations on SEH, and always get a reaction when I tell them to catch only what they can reasonably handle. At the latest presentation I did, someone pointed out that VS.NET automatically puts in a "catch e as Exception" clause for VB.NET applications! This should be at the top of the list for things the VS.NET team should remove.

Kirk Allen Evans

# re: What do you think of .NET's exception model? @ Wednesday, January 28, 2004 9:01 PM

Kirk, I will look into the feasability of getting that removed from VB.NET's VS autocomplete feature. Regardless of .NET programming language, if your compiler supports try-catch and your VS IDE integretation contains autocomplete features then you should certainly adhere to correct (and safe) exception handling code patterns by default! We'll see what the VB.NET team has to say about this. Thanks for the feedback!

Charles Torre

Anonymous comments are disabled
Page view tracker