n <- 7

result = tryCatch({
    z = divideby(n)
}, warning = function(w) {
    ## warning-handler-code
    # <do nothing>
    z
}, error = function(e) {
    ## error-handler-code
    # return NA
    return(NA)
}, finally = {
    ## cleanup-code
    # do nothing
} )


# eg

divideby <- function(x) {
  if (x == 0)
    stop ("cannot divide by 0")

  if (x < 0 )
    warning("negative number.")

  return(10 / x)
} 


sapply(-3:10, function(n)

tryCatch({
    divideby(n)
}, warning = function(w) {
    ## warning-handler-code
    # <do nothing>
}, error = function(e) {
    ## error-handler-code
    # return NA
    return(NA)
}, finally = {
    ## cleanup-code
    # do nothing
} )

  )
