TODO #1065

    Error handling statement (%1) could not be converted properly. A throw statement was generated instead.

    Description

    This EWI is generated when an error handling statement is too complex or if it is a pattern that is not supported by the VBUC.

    Recommendations

    Most occurrences of this EWI will require manual changes to the source code to fix the issue. However, most cases of an error label that is globally called within a function can be replaced by a single try { } catch statement with the addition of return statements where appropriate.

    The code example illustrates such an example.

    Sample VB6

    PublicFunction ErrorHandlingStatement() AsString

    Dim ObjD AsInteger

    OnErrorGoTo LabelErr

    LabelStart:

    ObjD = ErrRaisableSub

    LabelExit:

    ExitFunction

    LabelErr:

    If ObjD = 1 Then

    Resume LabelStart

    Else

    Resume LabelExit

    EndIf

    EndFunction

    Target VB.NET

    PublicFunction ErrorHandlingStatement() AsString

    Dim ObjD AsInteger

    OnErrorGoTo LabelErr

    LabelStart:

    ObjD = ErrRaisableSub()

    LabelExit:

    ExitFunction

    LabelErr:

    If ObjD = 1 Then

    Resume LabelStart

    Else

    Resume LabelExit

    EndIf

    EndFunction

    Expected VB.NET

    One way of changing this error patern to ensure functional equivalence is:

    PublicFunction ErrorHandlingStatement() AsString

    Dim ObjD AsInteger

     

    Try

    ObjD = ErrRaisableSub()

    Catch

    If ObjD <> 1 Then

    Return"FAILED"

    EndIf

    EndTry

    Return"OK"

    EndFunction

    Target C#

    staticpublicstring ErrorHandlingStatement()

    {

    int ObjD = 0;

    //UPGRADE_TODO: (1065) Error handling statement (On Error Goto) could not be converted properly. A throw statement was generated instead.

    thrownewException("Migration Exception: 'On Error Goto LabelErr' not supported");

    ObjD = ErrRaisableSub();

    LabelExit:

    return"OK";

    LabelErr:

    if (ObjD == 1)

    {

    //UPGRADE_TODO: (1065) Error handling statement (Resume) could not be converted properly. A throw statement was generated instead.

    thrownewException("Migration Exception: 'Resume LabelExit' not supported");

    }

    return"FAILED";

    }

    Expected C#

    One way of changing this error patern to ensure functional equivalence is to do the following changes:

    staticpublicstring ErrorHandlingStatement()

    {

    int ObjD = 0;

    try

    {

    ObjD = ErrRaisableSub();

    }

    catch (Exception)

    {

    if (ObjD != 1)

    {

    return"FAILED";

    }

    }

    return"OK";

    }


    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