fixed catching of undefined errors