---
schema_version: "1"
id: c0e6a6e24d9e577b6dfdb418c46139f322a50a1395b3cec54065c55fa8e58dba
title: fail
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-runtime-functions-fail.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-runtime-functions-fail
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 5b977cd24c83d30e73c3986fa385fe3f9b2de3e8e74931f7d4eee8f2cbfab0bf
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# fail

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## fail(message: String = 'Error'): Nothing

Throws an exception with the specified message.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>message</code></p></td><td><p>An error message (<code>String</code>).</p></td></tr></tbody></table>

### Example

This example returns a failure message `Data was empty` because the expression
`(sizeOf(myVar) <= 0)` is `true`. A shortened version of the error message is shown in the output.

#### Source

```DataWeave
%dw 2.0
import * from dw::Runtime
var result = []
output application/json
---
if(sizeOf(result) <= 0) fail('Data was empty') else result
```

#### Output

```TXT
ERROR 2018-07-29 11:47:44,983 ...
*********************************
Message               : "Data was empty
...
```
