Exceptions triggered by undefined variable should be handled before FATAL error

this is a enhancement of the fix for bug #64135