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

<< Click to Display Table of Contents >>

Navigation:  Code Virtualizer > FAQ > General >

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

Switch-Case statements and try-except clauses cannot work with Code Virtualizer macros in most compilers.

 

Compilers generate a direct jump table in the data section which directly jumps to each "case" statement. When the code is virtualized, the jump goes into a virtualized (garbage) code and it produces exception. You can use a workaround to protect your switch-case statements with Code Virtualizer macros, like:

 

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

 

}