fixing undefined variable in a catch block