Skip to content

Exit (stop script execution)

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

Immediately stops script execution. Instead of wrapping the entire script in a function just to use return, call Exit() wherever you need early termination.

ParameterTypeRequirementExplanation
exitCodenumberoptionalExit code. 0 (default) is a clean exit. Any non-zero value logs an error with the code.

NOTE

It is not necessary to call Exit() at the end of a script. The engine exits automatically when the last line is reached. Exit() is useful for early termination based on conditions or errors.

IMPORTANT

Exit() and Exit(0) are equivalent clean exits. Use Exit(1) (or any non-zero value) to signal an error condition to the host application. The non-zero code is written to the script log.

Example

ts
var ok = ListDir("/incoming");
if (!Array.isArray(ok)) {
  Log.Error("could not list directory");
  Exit(1);
}

ok.forEach(function(item) {
  Log(item.Name);
});

// No explicit Exit() needed here — the script ends naturally