stopTwMisc: stopTwMisc

Description Usage Arguments Details Author(s) Examples

View source: R/debug.R

Description

Extension of stopCustom to generates error of given subclass of "twMiscError"

Usage

1
stopTwMisc(..., subClass = character(0), call = sys.call(-1))

Arguments

...

further arguments concatenated to a message

subClass

string vector: subClasses of error, (with most specific first)

call

frame where the error occured

Details

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

Author(s)

Thomas Wutzler

Examples

 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)  
)    

twMisc documentation built on May 2, 2019, 6:11 p.m.