On Error Resume Next

In times past, when Visual Basic was the top-of-the-line development environment, and then again when VBA was the king of Active Server Pages (ASP), error handling was... less structured than you might see today.

The On Error Statement from Visual Basic gives you a few ways to handle errors.

The first is to set up an error handler, which is a section of code within the same function that will get called when an exception is raised (thrown). You can turn this on and off during the function execution, and you can resume at the next line or at some specific point.

The second is to use On Error Resume Next, which basically means that the Err variable will be set after any error and you can handle it explicitly. This was the only method of error handling in ASP, so over time I got good at writing clean code with this.

These days when I talk about On Error Resume Next error handling I'm usually jokingly referring to some code that is simply ignoring errors and continuing, which is something that some unfortunate VB code was written to do when people got lazy/desperate.

Here's an example of this in C# for example.

try {
  doSomethingDangerous();
catch (Exception) {
  // ignore
}

Without correcting, compensating, or even logging, this is a clear example of On Error Resume Next-programming.

Happy error handling!

Tags:  codingerrors

Home