stopping R execution but not shiny display

I have script.R I source in another shiny script:
`tryCatch(
{
con <- DBI::dbConnect(odbc::odbc(),"M3",uid = uid)
},
error = function(e) {
sortie <<- "connexion odbc non établie"
e <<- e
sortie

}
)

tryCatch(
{
con <- DBI::dbConnect(odbc::odbc(),"M3",uid = uid)

},
error = function(e) {
sortie <<- "connexion odbc non établie2"
e <<- e
}`

I don't want the second block to execute if it catches an error in the first one. so I put stop in the error brackets. That stops also my shiny script displaying the error! what should I do to keep the shiny script executing and stop only the script.R?

Nest the second try-catch inside the first one?

It will be impractical as I have 6 ones in my script separeted by other pieces of code

Create a global flag variable with initial value true. Set the flag to false in the first catch. Test the flag before executing any code that should be suppressed in the event of an error.

This might not work in every situation, but if you are raising the error as e you could put if_else(inherits(e, "condition"), pass, tryCatch({...})) around each of the error handlers. And remove the exit call from the first one. This should cause it to skip any of the error handlers once it catches the first one.