VB6 Error Handling uses a number of statements that are not supported in C#:
The tool may suppress these upgrade transformations if it determines doing so will break the build. For example, the OERN is not applied if the protected code has a return in a lambda expression. When the Error Handling Upgrade cannot be applied automatically, the tool will add UPGRADE_TODO comments to the translation. Note that VB.NET translations retain On Error statements by default. VB.NET translations may be made to use try/catch by adding a <Select UseTryCatch="on"/> command to the translation script.
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>
The <Select ExceptionHandling command specifies how the analyzer should deal with exception handling. It possible values are the ExceptionType enumeration whose entries are as follows:
Entry | Description |
Simple | Indicates that logic to set the VBNET.Error object will not be authored. (default) |
SetErrorObject | Indicates that logic should be authored in try/catch blocks so that the VBNET.Err object will be set to reflect the error number. |
UseTryCatch | Indicates that the tool should use Try-Catch as opposed to On Error GoTo style error handling for VBN translations. In essence, this switch tells the analyzer to use the same analyzer method that is presently used for CSH for VBN as well. |
When the SetErrorObject exception type is active the first statement of each catch block has a call to gmRTL.Core.GlobalException.SetErrorObject included. Thus, for example, a simple block becomes
catch(Exception exc) { gmRTL.Core.GlobalException.SetErrorObject(exc); }