4.9. Exception Handling

Exception handling has been improved in .NET 4.0 with the introduction of the System.Runtime.ExceptionServices namespace, which contains classes for advanced exception handling.

4.9.1. CorruptedStateExceptions

Many developers have written code such as the following:

try
{
// do something that may fail
}
catch(System.Exception e)
{
...
}

(OK, I might have done this, too.) This is almost always a very naughty way to write code because all exceptions will be hidden. Hiding exceptions you don't know about is rarely a good thing, and if you do know about them, you should inevitably be handling them in a better way. Additionally, there are some exceptions that should never be caught (even by lazy developers), such as lowdown ...

Get Introducing .NET 4.0: with Visual Studio 2010 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.