I've done a lot of work with MSIL in the past, and I don't recommend that you take language specific shortcuts. When you do, the compiler spits out a load of support code to make it work correctly. Take a look at the MSIL produced with C# (no on error resume next) and VB.Net
C# (24 lines)
.method private hidebysig instance void Form1_Load(object sender, class [mscorlib]System.EventArgs e) cil managed
{
.maxstack 1
.locals init (
[0] class OnErrorCTest.Form1 form,
[1] class [mscorlib]System.Exception err)
L_0000: nop
L_0001: nop
L_0002: ldnull
L_0003: stloc.0
L_0004: ldloc.0
L_0005: callvirt instance string [System.Windows.Forms]System.Windows.Forms.Control::get_Text()
L_000a: call void [mscorlib]System.Console::WriteLine(string)
L_000f: nop
L_0010: nop
L_0011: leave.s L_0018
L_0013: stloc.1
L_0014: nop
L_0015: nop
L_0016: leave.s L_0018
L_0018: nop
L_0019: ret
.try L_0001 to L_0013 catch [mscorlib]System.Exception handler L_0013 to L_0018
}
VB
(63 lines!)
.method private instance void Form1_Load(object sender, class [mscorlib]System.EventArgs e) cil managed
{
.maxstack 3
.locals init (
[0] class OnErrorTest.Form1 form,
[1] int32 VB$ActiveHandler,
[2] int32 VB$ResumeTarget,
[3] int32 VB$CurrentStatement)
L_0000: nop
L_0001: call void [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.ProjectData::ClearProjectError()
L_0006: ldc.i4.s -2
L_0008: stloc.1
L_0009: ldc.i4.2
L_000a: stloc.3
L_000b: ldloc.0
L_000c: callvirt instance string [System.Windows.Forms]System.Windows.Forms.Form::get_Text()
L_0011: call void [mscorlib]System.Console::WriteLine(string)
L_0016: nop
L_0017: leave.s L_007d
L_0019: ldloc.2
L_001a: br.s L_001f
L_001c: ldloc.2
L_001d: ldc.i4.1
L_001e: add
L_001f: ldc.i4.0
L_0020: stloc.2
L_0021: switch (L_0036, L_0001, L_0009, L_0017)
L_0036: leave.s L_0072
L_0038: ldloc.3
L_0039: stloc.2
L_003a: ldloc.1
L_003b: ldc.i4.s -2
L_003d: bgt.s L_0042
L_003f: ldc.i4.1
L_0040: br.s L_0043
L_0042: ldloc.1
L_0043: switch (L_0050, L_001c)
L_0050: leave.s L_0072
L_0052: isinst [mscorlib]System.Exception
L_0057: ldnull
L_0058: cgt.un
L_005a: ldloc.1
L_005b: ldc.i4.0
L_005c: cgt.un
L_005e: and
L_005f: ldloc.2
L_0060: ldc.i4.0
L_0061: ceq
L_0063: and
L_0064: endfilter
L_0066: castclass [mscorlib]System.Exception
L_006b: call void [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.ProjectData::SetProjectError(class [mscorlib]System.Exception)
L_0070: leave.s L_0038
L_0072: ldc.i4 -2146828237
L_0077: call class [mscorlib]System.Exception [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.ProjectData::CreateProjectError(int32)
L_007c: throw
L_007d: nop
L_007e: ldloc.2
L_007f: brfalse.s L_0086
L_0081: call void [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.ProjectData::ClearProjectError()
L_0086: ret
.try L_0001 to L_0052 filter L_0052 handler L_0066 to L_0072
}
Synergy Editor - Available in the WIP forum