# try_call_catch · Rell standard library · Chromia Docs (concept)

> function try_ call_ catch<T>(fn: () -> T): try_call_result <T> Safely call a function that may fail (i.e. that may throw an exception), returning a result 

Source: https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/root/try_call_catch/

FUNCTION

# try\_call\_catch

```signature
function try_call_catch<T>(fn: () -> T): try_call_result<T>
```

Safely call a function that may fail (i.e. that may throw an exception), returning a result that can be
inspected for errors.

Accepts 0-ary function references, i.e. references to functions of type `() -> T`, and returns a
`try_call_result<T>` which wraps
either the return value of the function, or error information if the function threw an exception.

Only exceptions of type `require` are caught, and any other exceptions are re-thrown. Use `try_call()`
variants if you want to handle
all exceptions.

Changes to the database that occur during the call are rolled back when an exception is thrown.

Examples:

Rell

```
function fails(): integer {
    require(false, "This fails");
    return 0;
}
function succeeds(): integer { return 17; }
try_call_catch(fails(*)) // returns a try_call_result containing the error message
try_call_catch(succeeds(*)) // returns a try_call_result containing 17
// `fn` can also be written as a lambda:
try_call_catch(() -> { require(false, "This fails"); 0 }) // try_call_result containing the error message
try_call_catch(() -> 17) // returns a try_call_result containing 17
```

**Parameters**

* **fn** — the function to be called

**Returns**

a `try_call_result<T>` containing either the return value of `fn` or error information

Since 0.14.16

[View this page on docs.chromia.com](https://docs.chromia.com/pages/rell-stdlib/-rell%20-system%20-library/%5Broot%5D/try_call_catch.html)Generated API reference, mirrored from the live docs
