NetSuite Development Error Handling

As mentioned in a previous article, SuiteScript, which is used for NetSuite development, is a javascript-based language, and the try-catch syntax commonly used in javascript can be used for error handling. However, the try-catch syntax is not used.

However, while the try-catch syntax can be used to branch processing at the point where an error occurs, it is not possible to determine which part of the code or processing is actually at fault.

Therefore, NetSuite includes by default a function that outputs a specific log. Depending on the log level, the function can output the contents of errors, variables, etc., which is very useful for development. The log output can be viewed from the script detail setting screen, so users who are not involved in development will not see the log, avoiding confusion.

Also, since the log level can be freely set, it can be implemented in such a way that logs are output at the Debug level in the development environment, while logs are output at the Error level in the production environment.

In addition, if a problem occurs in a user event script or other script involved in a transaction, the NetSuite screen will indicate the line in the script that caused the problem, in addition to the content of the error. This is also implemented by default, so you can proceed with development without wasting time if a script does not behave as intended.