I wanted to know if there is a way to execute something after an error ocurred.
I am currently working with some databases and I need to liberate resources after an error, with a statement like dbDisconnect(database)
Thank you
I wanted to know if there is a way to execute something after an error ocurred.
I am currently working with some databases and I need to liberate resources after an error, with a statement like dbDisconnect(database)
Thank you
Use a tryCatch
with the finally
block
tryCatch({
# some code that initializes database
# some code that runs a query
}, finally = dbDisconnect(database) )
The expression inside finally
gets run regardless of whether the code in the try block was successful or threw an error.