Fixed undefined variable when catching error