How to use option(error = ...) properly

Does anyone have experiences with using option(error = function()) properly? I want to write errors to a logfile and then terminate as usually. Currenlty I use

  options(error = function(...) {
    lg$fatal("Unknown Error in '~/scripts/check_gvrail_ftp.R'", error = geterrmessage())  # nervermind this line
    options(error = NULL)
    stop(geterrmessage())
  })

But resetting the option and calling stop() again looks like a cheap hack to me. I also tried q("no", status = 1, runLast = FALSE) instead, but this quits the session in RStudio server. Does anyone know of a better way to do this?