error.create(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a new error.SuiteScriptError object, which can be used in a try-catch statement to abort script execution.

Note this method creates a new error, but does not throw the error. Your script code will need to include logic to throw the error when appropriate.

Returns

An error.SuiteScriptError object.

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/error Module

Since

2015.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.message

string

required

Error message text displayed in the Details column of the Execution Log. Sets the value for the SuiteScriptError.message property.

The default value is null.

2015.2

options.name

string

required

User-defined error code. Sets the value for the SuiteScriptError.name property.

2015.2

options.notifyOff

boolean

optional

Sets whether email notification is suppressed. If set to false, the system emails the users identified on the applicable script record’s Unhandled Errors subtab when the error is thrown. The default values is false.

For additional information about the Unhandled Errors subtab, see Creating a Script Record.

2015.2

Errors

Error Code

Thrown If

SSS_MISSING_REQD_ARGUMENT

The options.message or options.name parameter is not specified.

WRONG_PARAMETER_TYPE

One of the parameters is not specified as the correct type:

  • options.message must be a string value

  • options.name must be a string value

  • options.notifyOff must be a boolean value

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/error Module Script Samples.

          //Add additional code 
...
// errorObj is a error.SuiteScriptError if this code is included in a server script that is not a user event script.
// errorObj is a error.UserEventError if this code is included in a user event script.

var custom_error = error.create({
    name: 'MY_ERROR_CODE',
    message: 'my custom error details',
    notifyOff: false
});
log.debug("Error Code: " + custom_error.name); // 'Error Code: MY_ERROR_CODE' will be logged
...
//Add additional code 

        

Related Topics

error.SuiteScriptError
N/error Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices