OdeToCode IC Logo

The System.Exception to the Rule

Tuesday, June 20, 2006

Two weekends ago, I did presentations on ASP.NET master pages and Windows Workflow at the MAD Code Camp in Reston, Virginia. A bit of .NET trivia came up during the workflow session when we talked about fault handlers and the types of exceptions we can throw and catch in .NET.

Despite the fact that this code:

static void Main(string[] args)
{
    
throw "You've done sometihng wrong!";
}

.. results in a compiler error (The type caught or thrown must be derived from System.Exception), the CLR itself has no such restriction. I planned on doing some research and putting together a blog post, but Jason Bock did all of the hard work already. See “Throwing Exceptions That Are Not Exceptions” – full IL code included.