Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Overview

VB6 Error Handling uses a number of statements that are not supported in C#:

  • On Error Goto <label> (aka. OEGT)
  • On Error Goto 0
  • On Error Resume Next (OERN)
  • Resume

There is a lot of details to consider in a discussion of how these are upgraded for C#. This article gathers some of details in one place.  This article is a work in progress.  If you would like to delve deeper into this topic, please contact us,.

Default Error Handling Upgrades

  • OEGT is migrated to a try/catch.  
  • On Error Resume Next is migrated to gmRTL.Core.ErrorHandling.ResumeNext 

The tool will suppress these upgrade transformations if it determines doing so will break the build due.  For example if the resulting code would have a return from a lambda expression.  

Suppressing the Default Error Handling Upgrade

One known case where the Error Handling migration may break the build is when the .NET logic uses a variable before it is initialized.  This can occur when the variable is used in the error handler or a goto block but the initialization is conditional.  In this case you may see something like this build error:

...\MyFile.cs(4397,23): error CS0165: Use of unassigned local variable 'foo'

There are a wide variety of ways to deal with this, but one quick work around is to suppress the automatic upgrade.  This is done using a Compile/Refactor command 

<Compile>
<Refactor>
    <Migrate id="VBPName.MyFile.Foo" RemoveOnErrorGoto="on"/>
</Refactor>
</Compile>



  • No labels