'R - how to execute specific code after error

In my function myFunc() I want to execute specific code after error.

myFunc code:

if (x > 10) {y <- x
} else {y <- 0}

But I want myFunc to execute like bellow:

if (x > 10) {y <- x
} else if (error) {y <- NA
} else {y <-0}

Is it possible in R?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source