throw_if_true <- function(param) {
# No else in tryCatch(): return a flag
ok <- tryCatch({
if (param) stop("test exception")
TRUE
}, error = function(e) {
cat("except\n")
FALSE
})
if (ok) cat("else\n")
}
throw_if_true(TRUE)
# except
throw_if_true(FALSE)
# else