Replace on.exit with tryCatch statement around polling