Skip to content

Exit()

ts
function Exit(exitCode?: number): void;

Instead of wrapping the entire script in a function() just to use return, Exit() immediately stops script execution.

The optional integer exitCode sets the exit code (defaults to 0). Any non-zero value indicates an error or a specific exit condition, and will be logged for debugging purposes. It is not necessary to use Exit() at the end of a script, as it will automatically exit when it reaches the end of the code block. However, Exit() is useful for early termination based on certain conditions or errors.

IMPORTANT

As of version 7.0.12, Exit() is the official and idiomatic way to stop script execution in Syncplify Server!. Avoid using return statements outside of function definitions, as they may lead to unexpected behavior or errors. Always use Exit() for clarity and consistency in your scripts.

Example

ts
{
  if (!Session) {
    // No session available, exit with error code 1
    Exit(1);
  }

  // Session is available, continue with script execution
  var user = Session.GetUser();
  if (!user) {
    // User information is missing, exit with error code 2
    Exit(2);
  }

  // Perform operations with the user object...
}