【问题标题】:Try catch in R for SQL statement尝试在 R 中捕获 SQL 语句
【发布时间】:2020-03-13 11:36:36
【问题描述】:

所有,

我正在尝试在 R 中为 Sql 语句添加 try catch。当它成功时,它应该返回 Success,否则返回失败。我尝试对其进行编码,但没有成功。谁能帮帮我.....

tryCatch({
sqlQuery(SQL, "exec [XXX].[CCC].[TABLEEEEE]", errors = FALSE)
},
error = function(err) showNotification("Success"))

我在下面也试过了,但没有用

expr = {
sqlQuery(SQL, "exec [XXX].[CCC].[TABLEEEE]")
},
error = function(e){ 
"Error"
}
)

谁能帮帮我.........

【问题讨论】:

    标签: r


    【解决方案1】:

    你错过了大括号吗?

        tryCatch({
    sqlQuery(SQL, "exec [XXX].[CCC].[TABLEEEEE]", errors = FALSE)
    },
    error = function(err) {showNotification("Success")})
    

    按照这个并检查运行的代码,

    tryCatch(
    expr = {
        # Your code...
        # goes here...
        # ...
    },
    error = function(e){ 
        # (Optional)
        # Do this if an error is caught...
    },
    warning = function(w){
        # (Optional)
        # Do this if an warning is caught...
    },
    finally = {
        # (Optional)
        # Do this at the end before quitting the tryCatch structure...
    }
    )
    

    【讨论】:

    • 谢谢。我试过但没有奏效。请参考我编辑的问题
    • 好的,哪个块跑了?
    • 如果成功,则不显示为 succes ,以防万一。它不仅显示为错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多