Skip to content
Prev 1372 / 12125 Next

[R-pkg-devel] best way the handle errors conditionally

On 06/03/2017 5:17 AM, Thierry Onkelinx wrote:
You could put the long set of commands into their own function, perhaps 
locally defined within the main function.  For example,

longset <- function() { ... }
if (transaction) {
     DBI::dbBegin(conn)
}
tryCatch(
   longset()
   error = function(e){
      if (transaction) {
        dbRollback(conn)
      }
      stop(e)
    }
)

Duncan Murdoch