stopCustom: stopCustom

Description Usage Arguments Author(s) Examples

View source: R/debug.R

Description

Extension of stop to generates error of given subclass

Usage

1
stopCustom(subClass = "simpleError", ..., call = sys.call(-1))

Arguments

subClass

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

...

further arguments concatenated to a message using pasteHead

call

frame where the error occured

Author(s)

Thomas Wutzler

Examples

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

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