TODO #1069

    Error handling statement (1%) was converted to a complex pattern which might not be equivalent to the original.

    Description

    This ussually occurs when a Resume Next Error Handling Pattern appears. It is a warning because functional equivalence could not be accomplished in this scenario.

    Recommendations

    The Resume Next error handling pattern resumes execution of the next statement after an error. In the case of structured error handling, the resulting behavior is more similar to an On Error Go To statement, where the catch statement serves as the Go To label.

    For this reason the replacement done by the VBUC might not be the exact funcional equivalent of the original code. In cases where the code is related, meaning if one call fails subsequent calls are likely to fail, then leaving a single try / catch statement could work. Since an error at any point of the process would merely be replicated in the susbsequent.

    A common example of this might be file operations, generally if the IO operation fails at the beginning, all subsequent calls will fail.

    In other cases, the error pattern of Resume Next is necessary when the code statements are fairly independent a failure in one statement does not affect the error condition of a subsequent call. The code sample illustrate such a case. In order to ensure functional equivalence it's necessary to add a try catch (with empty clause) to each line that can throw an exception. In these cases the main try catch (generated by the VBUC) is less effective and should be removed.

    Sample VB6

    PublicFunction ComplexErrorPattern() AsInteger

    F1(1)

     

    OnErrorResumeNext

     

    Dim I AsInteger

    I = 0

    I = F2(1)

     

    If I <> 0 Then

    I = F4(80)

    Else

    I = F3(50)

    EndIf

     

    Exit_Label:

    ComplexErrorPattern = I

    ExitFunction

    EndFunction

    Target VB.NET

    PublicFunction ComplexErrorPattern() AsInteger

    F1(1)

     

    'UPGRADE_TODO: (1069) Error handling statement (On Error Resume Next) was converted to a complex pattern which might not be equivalent to the original.

    Try

     

    Dim I AsInteger = 0

    I = F2(1)

     

    If I <> 0 Then

    I = F4(80)

    Else

    I = F3(50)

    EndIf

     

    Return I

    Catch exc As System.Exception

    ThrowNew Exception("Migration Exception: The following exception could be handled in a different way after the conversion: " + exc.Message)

    EndTry

    EndFunction

    Expected VB.NET

    PublicFunction ComplexErrorPattern() AsInteger

    Dim I AsInteger = 0

    Try

    I = F1(1)

    Catch

    EndTry

     

    If I <> 0 Then

    Try

    I = F2(80)

    Catch

    EndTry

    Else

    Try

    I = F3(50)

    Catch

    EndTry

    EndIf

     

    Return I

    EndFunction

    Target C#

    publicint ComplexErrorPattern()

    {

    F1(1);

    //UPGRADE_TODO: (1069) Error handling statement (On Error Resume Next) was converted to a complex pattern which might not be equivalent to the original.

    try

    {

    int I = 0;

    I = F2(1);

     

    if (I != 0)

    {

    I = F4(80);

    }

    else

    {

    I = F3(50);

    }

    return I;

    }

    catch (Exception exc)

    {

    thrownew Exception("Migration Exception: The following exception could be handled in a different way after the conversion: " + exc.Message);

    }

    return 0;

    }

    In this case it may be necessary to add a try catch block for the call to F2, F3 and F4, if the function can throw an exception.

    Expected C#

    staticpublicint ComplexErrorPattern()

    {

    int I = 0;

    try

    {

    I = F1(1);

    }

    catch

    {

    }

    if (I != 0)

    {

    try

    {

    I = F2(80);

    }

    catch

    {

    }

    }

    else

    {

    try

    {

    I = F3(50);

    }

    catch

    {

    }

    }

    return I;

    }


    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration