Skip to content

Can Code Virtualizer macros protect switch statements and try-except clauses?

Switch statements and try-except clauses do not work inside Code Virtualizer macros with most compilers.

Compilers may generate a jump table in the data section that points directly to each case. After virtualization, those entries point into virtualized code and cause an exception. As a workaround, protect the code inside each case separately:

switch (var)
{

    case 0:

    VIRTUALIZER_START

    // your code

    VIRTUALIZER_END

    case 1:

    VIRTUALIZER_START

    // your code

    VIRTUALIZER_END

    ...

}

For try-except clauses:

try
{

    VIRTUALIZER_START

    // your code

    VIRTUALIZER_END

}

except

{

    VIRTUALIZER_START

    // your code

    VIRTUALIZER_END

}