VB has a "On Error Resume Next", which tells each line to swallow exceptions and just keep executing to the next line. It's kind of like a try-catch around every single line.
It may be tempting for C++ developers to make fun of VB for this, but this is a lot like programming with HRESULT (or any error handling strategy based on return codes) when you forget to check the return value. And as we look at the codegen below, VB's code could turn out to be even more efficient than the unmanaged error handling equivalent.
So in this VB snippet, the exception is is swallowed and "Next" is printed.
On Error Resume Next
Throw New Exception("Bong!")
If you're wondering what the codegen is like, you can always compile and then view the IL in ildasm. Or you can view it in Reflector as C# instead of IL, which is easier to comprehend.
public static void Main()
// This item is obfuscated and can not be translated.
int VB$ActiveHandler = -2;
VB$CurrentStatement = 2;
VB$CurrentStatement = 3;
throw new Exception("Bong!");
VB$CurrentStatement = 4;
VB$ResumeTarget = 0;
switch ((VB$ResumeTarget + 1))
VB$ResumeTarget = VB$CurrentStatement;
switch (((VB$ActiveHandler > -2) ? VB$ActiveHandler : 1))
catch (object obj1) when (?)
if (VB$ResumeTarget != 0)
So you can see it's just putting the entire region in a try/catch block, and then using a switch table to jump back to the appropriate line. It has a "Current Statement" variable to track the last successful line to execute before an exception may have been thrown, and then switches to the next line on the exception path.
The switch table may seem evil at first, but remember that in native code, all those IfFailGoto() checks to propagate return results also add up to a lot of switching code. In this case, the branches are at least optimized into a single switch table as opposed to scattered branch code.