开发者

How to catch an error/exception in R? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Exception handling in R

Does an开发者_运维技巧yone have idea on how to catch an error or an exception in R?


Like Joshua said: use tryCatch. Include an error argument, which should be a function accepting one parameter (the error, typically called e).

tryCatch(
  stop("you threw an error"), 
  error = function(e) 
  {
    print(e$message) # or whatever error handling code you want
  }
)


It really depends on what you mean by "catch". Look at tryCatch and withCallingHandlers.


Have you looked into stop? This will allow you to catch exceptions that you define.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜