error.create(options)

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. You can create a custom name such as "My_Custom_Error" or use the values in the error.Type enum. Sets the value for the SuiteScriptError.name property.

2015.2

options.notifyOff

boolean

optional

Sets whether email notification is suppressed. Sets the value for the SuiteScriptError.notifyOff property.

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 
...
var custom_error = error.create({
    name: 'MY_ERROR_CODE',
    message: 'my custom error details',
    notifyOff: false
});
... 
try {
    // add additional try code
}
catch (e) {
    // add catch code to include the a log or throw statement, such as:
    throw custom_error;
    log.debug("Error Code: " + custom_error.name);
}
...

// You could also create the custom error within a throw statement:
// throw error.create({
//      name: 'MY_ERROR_CODE',
//      message: 'my custom error details',
//      notifyOff: false
// }); 

        

Related Topics

General Notices