Description Usage Arguments Details Author(s) Examples
Extension of stopCustom
to generates error of given subclass of "twMiscError"
1 | stopTwMisc(..., subClass = character(0), call = sys.call(-1))
|
... |
further arguments concatenated to a message |
subClass |
string vector: subClasses of error, (with most specific first) |
call |
frame where the error occured |
This function demonstrates how to write a custom error function to simplify raising package-specific errors
Handlers can check of twMiscError to handle all those errors.
With explicitly specifying subClass=<mySubClass>
, specific conditions can be caught.
See the source code by typing stopTwMisc
Thomas Wutzler
1 2 3 4 5 6 7 8 9 10 11 | myLog <- function(x) {
if (!is.numeric(x)) stopTwMisc("myLog() needs numeric input, but input was ",x)
if (any(x < 0)) stopTwMisc(subClass="invalidValue", "myLog() needs positive inputs, but input was ",x)
log(x)
}
tryCatch(
myLog(c(a=1,b=-3))
#,invalidValue = function(condition) "invalid value"
,twMiscError = function(condition) paste("subclass of twMiscError:", condition$message)
,error = function(condition) paste("general error:", condition$message)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.