Convert var_context_factory to RAII, wrap the var_context creation in an appropriate try/catch block