RaiseError Function

The RaiseError function uses error handling to stop the processing of a job and allows the generation of a custom error message. If it is not desired to stop the entire job, the optional boolean value (2 below) can be defined with a “true” value to stop the send for the current subscriber where the error occurred.

Syntax:

                    

RaiseError(1,2,3,4,5)
1 = Error message to display
2 = Indicates whether or not to stop the send on the individual level. A “true” value stops the skips the send for the current subscriber where the error occurred and moves on to the next subscriber. A value of false stops the entire send and returns the error message (1). If no value is defined, the function defaults to false.
3 = API Error code returned
4 = API Error number returned
5 = (When using AMPscript functions such as InsertDE, InsertData, UpsertDE, UpsertData) A true value allows the data to be written to the data extension before the error occurs. A false value does not allow the data to be written to the data extension before the error occurs. 

                

Example:

                    

%%[
if Empty(@couponRow) then
   RaiseError(“No coupons available”, false) 
else 
   SET @Code = Field(@couponRow, “CouponCode”)
endif
]%%
%%=v(@Code)=%%

                

Output:

No coupons available

Explanation:

This RaiseError function is used with the ClaimRow function and if the data extension has run out of coupon codes to use since all of the rows have been locked, the RaiseError function will return the string of “No coupons available.”

Because we want to stop the job if it errors so that no emails are sent out without coupon codes, the value of “false” is used in the second ordinal.

Leave a Reply

Your email address will not be published. Required fields are marked *