Fix unbound variable in exception handling