N/error Module Members Reference for SuiteScript Development
The N/error module in SuiteScript enables custom error handling using SuiteScriptError objects and provides essential logging capabilities.
The N/error module is critical for developers working with SuiteScript, as it provides tools for creating and handling custom errors within scripts. While this module does not throw custom errors directly, it offers a structured way to define and encapsulate errors, making it easier to manage exceptions through try-catch statements. This distinction helps ensure script executions can be handled gracefully without unexpected interruptions.
How to Use the N/error Module
The N/error module includes members that are essential for defining error types and handling script execution issues. Understanding these members is key to leveraging the module effectively in your SuiteScript projects:
N/error Module Members
| Member Type | Name | Return Type / Value Type | Supported Script Types | Description |
|---|---|---|---|---|
| Object | error.SuiteScriptError | Object | Server scripts | Encapsulates a custom SuiteScript error for any server script type. |
| Method | error.create(options) | error.SuiteScriptError | Server scripts | Creates a new error.SuiteScriptError object. |
| Enum | error.Type | enum | Server scripts | Holds string values for error types, to set the name parameter of the error.create(options) method. |
SuiteScriptError Object Members
The SuiteScriptError object provides additional properties to retrieve detailed information about errors when they occur:
| Member Type | Name | Return Type / Value Type | Supported Script Types | Description |
|---|---|---|---|---|
| Property | SuiteScriptError.cause | string (read-only) | Server scripts | Describes the cause of the error. |
| Property | SuiteScriptError.id | string (read-only) | Server scripts | Automatically generated error ID. |
| Property | SuiteScriptError.message | string (read-only) | Server scripts | Displays error message text from the options.message parameter during error creation. |
| Property | SuiteScriptError.name | string (read-only) | Server scripts | Represents the error name or code set from the options.name value during error creation. |
| Property | SuiteScriptError.notifyOff | boolean (read-only) | Server scripts | Suppresses email notifications when set to true. |
| Property | SuiteScriptError.stack | Array of strings (read-only) | Server scripts | Lists method calls at the time the error was thrown. |
| Property | SuiteScriptError.type | error.Type (read-only) | Server scripts | Indicates the error type as error.SuiteScriptError. |
Best Practices
When implementing error handling in SuiteScript, consider the following best practices:
- Always encapsulate error handling logic within try-catch statements.
- Use custom error messages to clearly identify issues when they occur.
- Utilize the
notifyOffproperty judiciously to manage unnecessary email notifications.
This robust structure allows developers to handle errors smoothly, ensuring that scripts can recover or terminate gracefully without losing important execution context.
Related Topics
For further insights into error handling and logging, refer to the N/log module for enhanced logging capabilities during script execution.
Key Takeaways
- The N/error module is essential for custom error handling in SuiteScript.
- The error.SuiteScriptError object encapsulates details about errors.
- Members like error.create and error.Type help streamline error management.
- Always implement structured error handling with try-catch statements to maintain script stability.
Frequently Asked Questions (4)
How can I create a custom error using the N/error module in SuiteScript?
What is the role of the `SuiteScriptError` object in error handling?
When should I use the `notifyOff` property in SuiteScript error handling?
Can the N/error module be used for custom error handling in all types of NetSuite scripts?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
