Exit

Exits the current thread.

Exit ExitCode, ThreadId

Parameters

ExitCode

Type: Integer

If omitted, it defaults to 0 (zero is traditionally used to indicate success). Otherwise, specify an integer between -2147483648 and 2147483647 that is returned to its caller when the script exits. This code is accessible to any program that spawned the script, such as another script (via RunWait) or a batch (.bat) file.

ThreadId

Type: Integer

If omitted, the current pseudo-thread exits. Otherwise, specify an exact A_ThreadId or a zero-based index in the current real thread's active pseudo-thread stack. Index 0 selects the oldest active pseudo-thread.

Remarks

Targeting an underlying pseudo-thread requests cooperative termination when that thread resumes and next processes events; it does not asynchronously abort managed code. A later request can replace its pending exit code. The function returns the target's exact thread ID, except when it exits the current thread immediately. An invalid target throws ValueError.

The Exit function terminates only the current thread. In other words, the stack of functions called directly or indirectly by a menu, timer, or hotkey function will all be returned from as though a Return were immediately encountered in each. If used directly inside such a function -- or in global code -- Exit is equivalent to Return.

If the script is not persistent and this is the last thread, the script will terminate after the thread exits.

Use ExitApp to completely terminate a script that is persistent.

ExitApp, OnExit, Functions, Return, Threads, Persistent

Examples

In this example, the Exit function terminates the call_exit function as well as the calling function.

#z::
{
    call_exit
    MsgBox "This MsgBox will never happen because of the Exit."
    call_exit() 
    {
        Exit ; Terminate this function as well as the calling function.
    }
}