use tryCatch instead of double on.exit