tryCatch抑制错误消息 [英] tryCatch suppress error message

查看:139
本文介绍了tryCatch抑制错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tryCatch 来捕获发生的任何错误。但是,即使我抓到并返回相应的错误值,看起来错误仍然在我的批处理系统的日志中报告。有没有办法完全抑制错误,只是继续处理我提供的错误?

I am using tryCatch to catch any errors that occur. However, even though I catch them and return the appropriate error value, it looks like the error is still reported in the logs of my batch system. Is there a way to completely suppress the error and simply proceed with the error handling I provide?

推荐答案

确保你不是(1)在错误处理代码中返回错误,(2)打印到 stderr 。注意这里有一个消息将其输出发送到 stderr

Make sure you're neither (1) returning an error, nor (2) printing to stderr in your error handling code. Note one gotcha here is message sends its output to stderr.

满足这两个条件的最小方法是 tryCatch(expr,error = function(e){})

A minimal way to fulfills both conditions is tryCatch(expr, error = function(e) {})

这篇关于tryCatch抑制错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆