---
schema_version: "1"
id: 08d9d3e58a6613f0cadd0cdfa6ef8cb65eb87d923b731c4b6adc4499671f676f
title: RaiseError
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/utilities/mc-ampscript-reference-utilities-raise-error.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-utilities/mc-ampscript-reference-utilities-raise-error.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3aa45ded6ee43bf55615d166b03dc1d88a519cd46f67bafb72ea8e2f781f1448
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# RaiseError

Stops the processing of an email job or send and produces an error message. In journeys, this function removes a subscriber from only one send. It doesn’t remove them from other sends in the journey.

Email sends that result in this type of error aren’t counted as email usage in your billing utilization.

**important:** Marketing Cloud Engagement builds and pre-processes emails before it attempts to send them. Your tracking and reporting metrics include emails that weren’t sent as a result of this function being called.

We recommend that you use this function only to handle errors, not as a method of segmenting subscribers. Use query activities and exclusion lists to handle segmentation requirements.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>✅ Yes</td>
  </tr>
</table>

This function became available in Marketing Cloud Next during the Summer ’26 release (API version 67.0).

## Syntax

```
RaiseError(errorMessage,
           boolSkipCurrentOnly,
           apiErrorCode,
           apiErrorNumber,
           boolPreserveDataExt)
```

The `RaiseError()` function has these parameters:

- `errorMessage` (string): Required. The error message to display when the error is raised.
- `boolSkipCurrentOnly` (boolean): If `true`, the function skips only the subscriber for which the error was raised, and proceeds with the rest of the email job. If `false`, the function stops the entire email job when an error is raised. The default value is `false`.
- `apiErrorCode` (string): A user-defined API error code.
- `apiErrorNumber` (number): A user-defined API error number.
- `boolPreserveDataExt` (boolean): If `true`, the function retains information written to data extensions before the error occurs, even if the subscriber is skipped. If `false`, the function doesn’t retain data extension information recorded before the error. This parameter applies to information that is inserted, updated, upserted, or deleted using AMPscript functions.

## Usage

To use this function, pass it the string of text that you want to output when an error is found.

```
RaiseError("An error was found. Stopping send.")
```

Typically, you place the function at a point in your code where a condition is tested, such as an if-else block. In this example, the code searches for a value in a data extension. If the code finds a matching row, it sets a variable to equal a field from the data extension. Otherwise, it logs the error, raises an exception, and skips processing for the current subscriber.

```
%%[
  Var @data, @promoCode, @logDataExt
  Set @data = LookupRows("PromotionCodes", "EmailAddress", emailAddr)

  If RowCount(@data) > 0 then
    Set @promoCode = Field(@data, "Code")
  Else
    /* Log the error to a data extension before raising an error. This isn't
       required, but it's a good practice because it helps troubleshoot
       problems. */
    InsertDE(
        logDataExt,
        "JobID", jobid,
        "EmailName", emailname_,
        "SubscriberKey", _subscriberkey,
        "EmailAddress", emailaddr
    )

    /* Raise the error. The second operand indicates that the exception applies
       only to the current recipient rather than the entire job. */
    RaiseError("No promo code found, skipping subscriber.", true)
  EndIf
]%%
```
