Fix crash when a script exception was thrown in some situations.
Possible fix for regression.