---
schema_version: "1"
id: 53e23762ad18923c86b084c3e037818c912390787ded837934d856764819883f
title: Raise Error (<raise-error/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-raise-error.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-raise-error
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4e3f881382240ed6ef8e3daef2341cf775311c7df22ca67c873303e2ec1a216a
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Raise Error (<raise-error/>)

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

Generates a Mule error to indicate that a failure occurred.

You can customize the error’s description and type. Use this component to raise:

- Core runtime errors, such as `MULE:SECURITY` and `MULE:CONNECTIVITY`.

- Custom error types.

You cannot raise an error from another connector or module, such as `FILE:FILE_NOT_FOUND` or
`JSON:INVALID_SCHEMA`. You cannot use a connector’s existing namespace.

## Component XML

This component supports the following XML structure:

```xml
<raise-error
  type="MULE:CONNECTIVITY"
  description="Error description message" />
```

Raise Error (`<raise-error/>`) attributes are configurable through the UI and XML.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>Raise error</strong> (default)</p></td><td><p><code>doc:name</code></p></td><td><div><div><p>Editable name for the component to display in the canvas.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>doc:id</code></p></td><td><div><div><p>Automatically generated identifier for the component.</p></div></div></td></tr><tr><td><p><strong>Type</strong></p></td><td><p><code>type</code></p></td><td><div><div><p>The type of error.</p></div></div></td></tr><tr><td><p><strong>Description</strong></p></td><td><p><code>description</code></p></td><td><div><div><p>The error description.</p></div></div></td></tr></tbody></table>

## Examples

### Example: Raising an Error After an Invalid User Input

The following example of a driving lessons platform checks that the user is over 16 years old. The
flow raises a custom `PRECONDITIONS:INCORRECT_AGE` error when the user enters an age less than 16
years.

```xml
<http:listener-config name="HTTP_Listener_config">
  <http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="raise-error-example-flow">
  <http:listener config-ref="HTTP_Listener_config" path="/test"/>
  <choice> (1)
    <when expression="#[message.attributes.queryParams.age &lt; 16]"> (2)
      <raise-error type="PRECONDITIONS:INCORRECT_AGE" description="Minimum age of 16 required to drive" />
    </when>
    <otherwise > (3)
      <logger level="INFO" message="User age above 16 years. Allowed to drive"/>
    </otherwise>
  </choice>
  <error-handler >
    <on-error-continue enableNotifications="true" logException="true" type="PRECONDITIONS:INCORRECT_AGE"> (4)
      <logger level="INFO" message="Minimum age to drive is 16 years old"/>
    </on-error-continue>
    <on-error-continue enableNotifications="true" logException="true"  type="MULE:EXPRESSION"> (5)
      <logger level="INFO" message="The parameter age is missing or invalid"/>
    </on-error-continue>
  </error-handler>
</flow>
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>The Choice router components adds conditional processing to the flow.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>If the age parameter sent in the request is less than 16 (<code>http://localhost:8081/test?age=15</code>), the Raise Error component raises the error type <code>PRECONDITIONS:INCORRECT_AGE</code> with the description <code>Minimum age of 16 required to drive</code>.</td></tr><tr><td><i data-value="3"></i><b>3</b></td><td>If the age parameter is greater than 16 in the request (<code>http://localhost:8081/test?age=17</code>), a Logger component returns the default message <code>User age above 16 years. Allowed to drive</code>.</td></tr><tr><td><i data-value="4"></i><b>4</b></td><td>An On-Error Continue component matches the type of the error <code>PRECONDITIONS:INCORRECT_AGE</code> and executes the Logger component inside its scope. The Logger component logs the error message <code>Minimum age of 16 required to drive</code>.</td></tr><tr><td><i data-value="5"></i><b>5</b></td><td>If no age parameter is passed in the request (<code>http://localhost:8081/test</code>) the choice component automatically raises a <code>MULE:EXPRESSION</code> error when trying to evaluate the expression <code>#[message.attributes.queryParams.age &lt; 16]</code>. No age parameter was provided in the request, so its value is null.<div><p>Then, an On-Error Continue component matches the type of the error <code>MULE:EXPRESSION</code> and executes the Logger component inside its scope. The Logger component returns the message <code>The parameter age is missing or invalid</code>.</p></div></td></tr></tbody></table>

### Example: Raising an Error After Comparing Values

The following example makes a request to an API (https://unsecurebank.com/balance) and stores the
returned account balance in the _balance_ variable, then compares the variable with `payload.amount`
to determine if the operation is possible. The Choice router produces an
`ACCOUNT:INSUFFICIENT_FUNDS` error when a transfer amount surpasses the available balance,
preventing the transfer from taking place. The description dynamically provides failure details.

```xml
<flow name="raise-error-example-flow">
  <http:request url="https://unsecurebank.com/balance" target="balance"/>
  <choice>
    <when expression="#[payload.amount > vars.balance]">
      <raise-error type="ACCOUNT:INSUFFICIENT_FUNDS" description="#['Cannot transfer $(payload.amount) since only $(vars.balance) are available.']"/>
    </when>
  </choice>
  <http:request url="https://unsecurebank.com/transfer"/>
</flow>
```

## See Also

- [Mule Errors](https://docs.mulesoft.com/mule-runtime/latest/mule-error-concept)

- [Error Handler (<error-handler/>)](https://docs.mulesoft.com/anypoint-code-builder/acb-component-error-handler)
