Recode Protect

Recode Protect is a feature of Recode that allows recovery from code errors at run-time.

What does Recode Protect do?

Recode Protect provides a safety net for common code errors that manifest at runtime. It makes use of Structured Exceptions in order to be able to deal with failures that would normally be fatal to the process - such as access violations and floating point exceptions (if enabled).

A common scenario is code that accesses an unchecked NULL pointer:

Foo* pFoo = GetFoo();
pFoo->val = 42;

In the event that GetFoo() returns NULL, this code is likely to raise an access violation due to the attempted write to val at an invalid address. If Recode Protect is enabled it will allow you to suspend execution and modify the code causing the access violation and Recode:

Foo* pFoo = GetFoo();
if (pFoo)
    pFoo->val = 42;

Finally, continuing the debugger will retry the fixed function from a function higher up the stack. If everything works out you can continue debugging as if nothing happened.

How to use Recode Protect

If Recode Protect is available after an exception has been caught by the VS debugger you will see the following dialog:

_images/recovery_dialog.png

Once you press OK the debugger should break at the point at which the error occurred. If possible, fix the code responsible for the issue, Recode (wait for success) and continue the debugger.

Note

Not everything can be fixed via Recode Protect. A simple rule is that incorrect code can be fixed, but incorrect/corrupted data cannot. If memory becomes corrupted somehow there’s typically very little you can do to resolve the situation.