RaiseError

Pass an error message if an error occurs.

Syntax 

1RaiseError(1, 2, 3, 4)

Properties 

OrdinalTypeDescription
1StringRequired. The error message to pass.
2BooleanRequired. Indicates whether error applies to current message recipient or entire send job. If the value is true, the error applies only to the current message recipient. If the value is false, the error applies to the entire send job.
3StringRequired. A user-defined error code. Use this property to provide a short description of the error.
4NumberRequired. A user-defined error number. Use this property to provide an error code for reference purposes.

Example 

This code example attempts to set the value of a variable based on the recipient’s first name attribute. If the attribute isn’t found, the code logs the error to a data extension and raises an exception.

1<script runat="server">
2  var dataExt = "FailedSendLog";
3
4  // Specify the values that we want to log in the data extension.
5  var logAttributes = {
6    Names: [
7      "JobID",
8      "EmailName",
9      "SubscriberKey",
10      "EmailAddress"
11    ],
12    Values: [
13      jobid,
14      emailname_,
15      _subscriberkey,
16      emailaddr
17    ]
18  };
19
20  // Set the value of the firstName variable.
21  try {
22    var firstName = Platform.Recipient.GetAttributeValue("FirstName");
23  } catch(e) {
24    Platform.Response.Write(Platform.Function.Stringify(e));
25  };
26
27  if (!firstName) {
28    try {
29      // Log the error to a data extension before raising an error. This isn't
30      // required, but it's a good practice because it helps troubleshoot
31      // problems.
32      Platform.Function.InsertDE(
33          dataExt,
34          logAttributes.Names,
35          logAttributes.Values
36      );
37
38      // Raise the error. The second operand indicates that the exception applies
39      // only to the current recipient rather than the entire job.
40      Platform.Function.RaiseError(
41          "First name missing",
42          true,
43          "Unable to obtain the first name attribute.",
44          100
45      );
46    } catch(e) {
47      Platform.Response.Write(Platform.Function.Stringify(e));
48    };
49  };
50</script>