Try Catch

Let's learn how to actually perform exception handling using try catch.

What are try and catch in R language?

try is a keyword that represents the handling of exceptions caused by errors or warnings during the execution of code. Using try we can avoid the unwanted termination of code abruptly however, the error message is still displayed.

Syntax for try

try(<exceptionCause>)
# Pass `try` the object that might throw an exception

Let’s have a look at an example:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy