Description Usage Arguments Author(s) Examples
Extension of stop
to generates error of given subclass
1 | stopCustom(subClass = "simpleError", ..., call = sys.call(-1))
|
subClass |
string vector: subClasses of error, (with most specific first) |
... |
further arguments concatenated to a message using |
call |
frame where the error occured |
Thomas Wutzler
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | myLog <- function(x) {
# handled by "error"
if (x[1]=="uncaughtClass") stopCustom(c("uncaughtClass"),x)
# handled by "twMiscError"
if (x[1]=="uncaughtTwMiscSublass") stopCustom(c("uncaughtSubClass",
"twMiscError"),x)
if (!is.numeric(x)) stopCustom(c("invalidClass","twMiscError"),
"myLog() needs numeric input, but input was",x)
if (any(x < 0)) stopCustom(c("invalidValue","twMiscError"),
"myLog() needs positive inputs, but input was",x)
log(x)
}
tryCatch(
#myLog(c("a","b"))
#myLog("uncaughtTwMiscSublass")
#myLog("uncaughtClass")
,invalidClass = function(c) "invalid class"
,invalidValue = function(c) "invalid value"
# important to catch specialized classes first
,twMiscError = function(c) "subclass of twMiscError"
,error = function(c) "subClass of error"
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.