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

> function assert_ fails<T>(fn: () -> T): failure Asserts a function fails; i.e. throws an exception. Example Application code Rell Copy // This will throw a

Source: https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/rell.test/assert_fails/

FUNCTION

# assert\_fails

```signature
function assert_fails<T>(fn: () -> T): failure
```

Asserts a function fails; i.e. throws an exception.

#### Example

##### Application code

Rell

```
// This will throw a exception.
function bad(): integer {
    return [0][1];
}
```

##### Test code

Rell

```
// This test will pass.
function test_bad() {
    rell.test.assert_fails(bad(*));
    // or inline:
    rell.test.assert_fails(() -> [0][1]);
}
```

**Parameters**

* **fn** — the function value to invoke

Since 0.11.0

---

```signature
function assert_fails<T>(expected_message: text, fn: () -> T): failure
```

Asserts a function fails; i.e. throws an exception; with a given exception message.

Verifies that the given exception message is a substring of the exception thrown by the given
function (if thrown).

#### Example

##### Application code

Rell

```
// This will throw a exception.
function bad(): integer {
    return [0][1];
}
```

##### Test code

Rell

```
// This test will pass.
function test_bad() {
    rell.test.assert_fails("out of bounds", bad(*));
    // or inline:
    rell.test.assert_fails("out of bounds", () -> [0][1]);
}
```

**Parameters**

* **expected\_message** — the expected substring of the error message
* **fn** — the function value to invoke

Since 0.11.0

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