general <- "You are wrong."
# returns silently
throw(general, character(0))
if (FALSE) {
throw(general)
specifics <- c("Detail 1.", i = "Detail 2.")
throw(general, specifics)
# embed R code with glue syntax
throw("`x` is {x}.", env = list(x = 1))
}
# add and retrieve additional argument
tryCatch(
{ throw(general, arg = "I'm an additional argument.") },
error = function(e) e$arg
)
Run the code above in your browser using DataLab