# R program to illustrate # Custom signal classes condition <- function(subclass, message, call = sys.call(-1), ...) { structure( class = c(subclass, "condition"), list(message = message, call = call), ... ) } is.condition <- function(x) inherits(x, "condition") custom_stop <- function(subclass, message, call = sys.call(-1), ...) { c <- condition(c(subclass, "error"), message, call = call, ...) stop(c) } check_log <- function(x) { if (!is.numeric(x)) custom_stop("invalid_class", "check_log() needs numeric input") if (any(x < 0)) custom_stop("invalid_value", "check_log() needs positive inputs") log(x) } tryCatch( check_log("ant"), # As we pass "ant", we will # get Numeric inputs # only are allowed as output # for input, if we give with negative value # let us check what happens, # for that uncomment below line and see, # obviously you get Positive # numeric value need to be provided #check_log("-100"), invalid_class = function(c) "Numeric inputs only are allowed", invalid_value = function(c) "Positive numeric value need to be provided" )