Errors and tryCatch
tryCatch handles errors and warnings. stop and warning raise them.
Example
res <- tryCatch({
stop("boom")
}, error = function(e) {
paste("caught:", conditionMessage(e))
}, finally = {
cat("done\n")
})
print(res)
print(tryCatch(as.integer("x"), warning = function(w) -1L))Exercise
Raise an error.
("message")Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.