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 …

Throwing exceptions

When reviewing some code today I noticed some code that catches an exception, does something with it and then explicitly throws it again. The code looked something like this: try { // Do something that might cause an exception } catch (Exception ex) { // Some stuff throw ex; } The problem with the above …

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 …

What is a DAL (Part 4)

As has been mentioned previously, one of the purposes of the DAL is to shield that application from the database. That said, what happens if a DAL throws an exception? How should the application respond to it? In fact, how can it respond to an exception that it should not know about? If something goes …

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 …

Friendly Error Messages (or not)

Microsoft are normally quite good at producing friendly error messages when things don’t work out. However today I rebooted my machine after installing security updates, I fired up Visual Studio and then attempted to open the solution I was working on. Visual Studio then complained that IIS wasn’t running ASP.NET 1.1. So I went to …