上級 › tryCatch の error ハンドラは warning を捕まえない › パターン5
tryCatch の error ハンドラは warning を捕まえない
tryCatch(expr, error = function(e) ...)のerrorハンドラは、条件クラスがerrorであるものしか捕まえません。
1 parse_int <- function(s) { 2 tryCatch({ 3 n <- as.integer(s) 4 n 5 }, error = function(e) { 6 -1 7 }_________________________) ^ 8 } 9 result <- parse_int("xyz") 10 cat("result:", result, "\n")
出力: result: NA
空欄を埋めて実行を通す
as.integer("xyz")が出す「NAs introduced by coercion」という警告はerrorハンドラでは捕まえられず、そのままNAが結果になります。
次の問題