---
schema_version: "1"
id: 5d2f1028162edb62705061d54ae939fe1e5cf5590e499a333bf95c42e3ada012
title: RaiseError
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/guides/mc-programmatic-content/ssjs_platformUtilityRaiseError.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformUtilityRaiseError.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9023c95312d6eef6100c0b6ee9174dab3455c081cd6f6da9e29f4d6b0b775e2f
products:
  - Marketing Cloud Engagement APIs and Programmatic Languages
  - Marketing Cloud
---
# 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.

```js
<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>
```
