Handling AggregateExceptions

I’ve written a couple of posts (see also) about how the AggregateException plays its part in exception handling in parallel systems. However, it has another trick up its sleeve when it comes to handling exceptions. AggregateException has a Handle method that takes a delegate of Func<Exception, bool> i.e. It takes an Exception as a parameter […]

Custom error pages and error handling in ASP.NET MVC 3

In ASP.NET MVC 3 a new bit of code appeared in the global.asax.cs file: public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } The above method is called from the Application_Start() method. Out of the box, what this does is set up a global filter for handling errors. You can still attribute controller methods or […]

Parallelisation in .NET 4.0 – Part 2 Throwing Exceptions

With more threads running simultaneously in an application there is increasing complexity when it comes to debugging. When exceptions are thrown you usually catch them somewhere and handle them. But what happens if you throw an exception inside a thread? Naturally, if you can handle the exception within the thread then that makes life much […]

The StackOverflowException

Take a look at the following code: class Program { static void Main(string[] args) { try { RecurseForever(); } catch (StackOverflowException) { Console.WriteLine(“Caught Stack Overflow Exception”); } catch (Exception) { Console.WriteLine(“Caught general Exception”); } Console.ReadLine(); } static void RecurseForever() { RecurseForever(); } } What do you think the output of the program will be? If […]

The try-catch-ignore anti-pattern (again!)

I’ve blogged about this a few times, but today I just want to highlight the frustration this causes on fellow developers. Earlier today I saw a tweet from Chris Canal that said: “Are you swallowing exceptions there?! Hold on, let me get something to break your fingers with 😐” [^] All too often I’ve seen […]

Crazy Extension Method

Here is an example of a crazy extension method that alters the semantics of method calling. First the extension method: public static class MyExtensions { public static bool IsNullOrEmpty(this string target) { return string.IsNullOrEmpty(target); } } Instead of calling the static method IsNullOrEmpty() on string, we are turning it around to allow it to be […]

Useless Error Message

Exception Processing Message 0xc0000013 Parameters 0x75BE023C 0x8343FCBC 0x75BE023C 0x75BE023C Well here’s a pointless error message from Microsoft Powerpoint 2007 running on Windows Vista. What actually happened is that I picked from the list of recently opened files a presentation that was saved to a USB key which is no longer present. While the dialog title […]