RaiseError

Pass an error message if an error occurs.

Syntax

RaiseError(1, 2, 3, 4)

Properties

Ordinal Type Description
1 String Required. The error message to pass.
2 Boolean Required. 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.
3 String Required. A user-defined error code. Use this property to provide a short description of the error.
4 Number Required. 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.

<script runat="server">
  var dataExt = "FailedSendLog";

  // Specify the values that we want to log in the data extension.
  var logAttributes = {
    Names: [
      "JobID",
      "EmailName",
      "SubscriberKey",
      "EmailAddress"
    ],
    Values: [
      jobid,
      emailname_,
      _subscriberkey,
      emailaddr
    ]
  };

  // Set the value of the firstName variable.
  try {
    var firstName = Platform.Recipient.GetAttributeValue("FirstName");
  } catch(e) {
    Platform.Response.Write(Platform.Function.Stringify(e));
  };

  if (!firstName) {
    try {
      // 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.
      Platform.Function.InsertDE(
          dataExt,
          logAttributes.Names,
          logAttributes.Values
      );

      // Raise the error. The second operand indicates that the exception applies
      // only to the current recipient rather than the entire job.
      Platform.Function.RaiseError(
          "First name missing",
          true,
          "Unable to obtain the first name attribute.",
          100
      );
    } catch(e) {
      Platform.Response.Write(Platform.Function.Stringify(e));
    };
  };
</script>