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"
),
invalid_class =
function
(c) "Numeric inputs
only are allowed",
invalid_value =
function
(c) "Positive numeric value
need to be provided"
)