RaiseError
This function enables the suppression or cancellation of an email send. It is useful for exception handling in your code, if an unexpected result occurs.
Arguments
RaiseError(1,2,3,4,5)
Ordinal | Type | Required | Description |
---|---|---|---|
1 | String | True | Error message to display or log (see note) |
2 | Boolean | False | Indicates whether the function skips the send for current Subscriber and continues or stops. A value of true skips the send for current Subscriber and moves to next Subscriber. A value of false stops the send and returns an error. The default value is false . |
3 | String | False | User defined API error code (see note) |
4 | Number | False | User defined API error number (see note) |
5 | Boolean | False | Indicates whether the function preserves Data Extension rows inserted, updated, or deleted by AMPscript functions before error occurs, even if the process skips the Subscriber. A value of 1 will preserve data operations to Data Extensions before the error is raised, even if the Subscriber is skipped. A value of 0 does not preserve operations before the error. |
NOTE: Arguments 1, 3 and 4 output by the function are not available from Send Tracking in Email Studio. Marketing Cloud Support will be able to advise of the function output.
NOTE: This function still counts as an email send, even if an email was not sent to a Subscriber. Only use this function for exception handling, not for segmenting or excluding a large number of Subscribers.
Example 1
The following example uses the ClaimRow function to allocate a coupon code value from a Data Extension to a Subscriber, if a coupon is available and not already assigned to the Subscriber’s email address. If the coupon has previously been assigned to the Subscriber, then the previously allocated coupon code is returned.
%%[
var @email, @couponRow, @couponCode
/* include the send context attributes or columns to record here */
set @email = AttributeValue("emailAddr")
set @couponRow = ClaimRow("CouponCodes", "IsClaimed", "EmailAddress", @email)
if not empty(@couponRow) then
set @couponCode = Field(@couponRow, "CouponCode")
else
RaiseError("No coupons available")
endif
]%%
Coupon code: %%=v(@couponCode)=%%
Output
If no coupon codes are available, the following message appears when previewing an email and the email send is aborted.
No coupons available
Example 2
Not a subscriber? Subscribe now.