Improve robustness of cross-context statement error handling