foo <- function() {
tryCatch({
stop("Woops!")
}, error = function(ex) {
cat("An error was caught: ", ex$message, "\n", sep="")
})
cat("Continuing...\n");
}
bar <- function() {
tryCatch({
abort("Woops!")
}, error = function(ex) {
cat("An error was caught: ", ex$message, "\n", sep="")
})
cat("This message will never be displayed...\n");
}
# An error generated by stop() can be caught
foo()
# ...which is not possible when using abort()
bar()
Run the code above in your browser using DataLab