Program termination: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 127: Line 127:
end f</lang>
end f</lang>
Memory is automatically managed and reclaimed by AppleScript.
Memory is automatically managed and reclaimed by AppleScript.

=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
Line 296: Line 297:


To end not just the current process, but all processes in the same group, do <lang C>exit_group();</lang>
To end not just the current process, but all processes in the same group, do <lang C>exit_group();</lang>

=={{header|C sharp|C#}}==
<lang csharp>if (problem)
{
Environment.Exit(1);
}</lang>


=={{header|C++}}==
=={{header|C++}}==
Line 324: Line 331:


Note that returning a value from main is mostly equivalent to calling <tt>std::exit</tt> with the returned value, except that automatic variables are correctly destructed. If one wants to return from an inner function, while still doing complete cleanup, a solution is to throw an exception caught in main (this will call the destructors of non-main local variables during stack unwinding), and to then return normally from main (which will destruct all automatic objects in main, and then do the cleanup like <tt>std::exit</tt>.
Note that returning a value from main is mostly equivalent to calling <tt>std::exit</tt> with the returned value, except that automatic variables are correctly destructed. If one wants to return from an inner function, while still doing complete cleanup, a solution is to throw an exception caught in main (this will call the destructors of non-main local variables during stack unwinding), and to then return normally from main (which will destruct all automatic objects in main, and then do the cleanup like <tt>std::exit</tt>.

=={{header|C sharp|C#}}==
<lang csharp>if (problem)
{
Environment.Exit(1);
}</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
Line 511: Line 512:
if problem ->
if problem ->
halt().</lang>
halt().</lang>

=={{header|F Sharp|F#}}==
<lang fsharp>open System

if condition then
Environment.Exit 1</lang>


=={{header|Forth}}==
=={{header|Forth}}==
Line 553: Line 560:
exit code is 1
exit code is 1
</pre>
</pre>

=={{header|F Sharp|F#}}==
<lang fsharp>open System

if condition then
Environment.Exit 1</lang>


=={{header|Gambas}}==
=={{header|Gambas}}==
Line 735: Line 736:
(and the stack trace follows)
(and the stack trace follows)
</pre>
</pre>

=={{header|GW-BASIC}}==
<lang qbasic>10 IF 1 THEN STOP</lang>


=={{header|Groovy}}==
=={{header|Groovy}}==
Line 747: Line 745:
Solution #1:
Solution #1:
<lang groovy>if (problem) Runtime.runtime.halt(intExitCode)</lang>
<lang groovy>if (problem) Runtime.runtime.halt(intExitCode)</lang>

=={{header|GW-BASIC}}==
<lang qbasic>10 IF 1 THEN STOP</lang>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 799: Line 800:
<lang javascript>if (some_condition)
<lang javascript>if (some_condition)
quit();</lang>
quit();</lang>



=={{header|jq}}==
=={{header|jq}}==
Line 897: Line 897:
The following is functional. Better practice is to instead jump to commands or subs to close known open files, windows etc, avoiding error messages as above.
The following is functional. Better practice is to instead jump to commands or subs to close known open files, windows etc, avoiding error messages as above.
<lang lb>if 2 =2 then end</lang>
<lang lb>if 2 =2 then end</lang>

=={{header|Logo}}==
=={{header|Logo}}==
{{works with|UCB Logo}}
{{works with|UCB Logo}}
Line 1,090: Line 1,090:


An exit without these cleanups can be done with <code>POSIX::_exit()</code> (as noted in <code>perlfunc.pod</code> under the normal <code>exit()</code>). This is the <code>_exit()</code> system call (which the C library generally provides in equivalent form on non-Unix/non-POSIX systems too).
An exit without these cleanups can be done with <code>POSIX::_exit()</code> (as noted in <code>perlfunc.pod</code> under the normal <code>exit()</code>). This is the <code>_exit()</code> system call (which the C library generally provides in equivalent form on non-Unix/non-POSIX systems too).

=={{header|Perl 6}}==
<lang perl6>if $problem { exit $error-code }</lang>
An <tt>exit</tt> runs all appropriate scope-leaving blocks such as <tt>LEAVE</tt>, <tt>KEEP</tt>, or <tt>UNDO</tt>,
followed by all <tt>END</tt> blocks, followed by all destructors that do more than just reclaim memory, and so cannot be skipped because they may have side effects visible outside the process. If run from an embedded interpreter, all
memory must also be reclaimed. (Perl 6 does not yet have a thread-termination policy, but will need to before we're done.)


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,209: Line 1,203:
(custodian-shutdown-all (current-custodian)))
(custodian-shutdown-all (current-custodian)))
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>if $problem { exit $error-code }</lang>
An <tt>exit</tt> runs all appropriate scope-leaving blocks such as <tt>LEAVE</tt>, <tt>KEEP</tt>, or <tt>UNDO</tt>,
followed by all <tt>END</tt> blocks, followed by all destructors that do more than just reclaim memory, and so cannot be skipped because they may have side effects visible outside the process. If run from an embedded interpreter, all
memory must also be reclaimed. (Perl 6 does not yet have a thread-termination policy, but will need to before we're done.)


=={{header|REBOL}}==
=={{header|REBOL}}==
Line 1,347: Line 1,348:
}
}
</lang>
</lang>

=={{header|Slate}}==
<lang slate>problem ifTrue: [exit: 1].</lang>


=={{header|Scheme}}==
=={{header|Scheme}}==
Line 1,384: Line 1,382:
Sys.exit(code);
Sys.exit(code);
}</lang>
}</lang>

=={{header|Simula}}==
=={{header|Simula}}==
<lang Simula>IF terminallyIll THEN terminate_program;</lang>»The procedure "terminate_program" terminates program execution. It&nbsp;closes SYSIN&nbsp;and&nbsp;SYSOUT.
<lang Simula>IF terminallyIll THEN terminate_program;</lang>»The procedure "terminate_program" terminates program execution. It&nbsp;closes SYSIN&nbsp;and&nbsp;SYSOUT.
&nbsp;&nbsp;It is implementation-dependent with respect to whether or not other open files are also closed.« [[http://simula67.at.ifi.uio.no/Standard-86/chap_10.htm| Simula Standard 86]]
&nbsp;&nbsp;It is implementation-dependent with respect to whether or not other open files are also closed.« [[http://simula67.at.ifi.uio.no/Standard-86/chap_10.htm| Simula Standard 86]]

=={{header|Slate}}==
<lang slate>problem ifTrue: [exit: 1].</lang>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Line 1,449: Line 1,451:
-> execution stops and message:
-> execution stops and message:
IF (condition==2) ERROR/STOP "condition ",condition, " Execution STOP "</lang>
IF (condition==2) ERROR/STOP "condition ",condition, " Execution STOP "</lang>

=={{header|Unlambda}}==
<lang unlambda>`ei</lang>
Note: the argument to the <code>e</code> function is the return value of the program; however many implementation simply ignore it.

There are no objects to be cleaned up.


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
Line 1,466: Line 1,462:
fi
fi
exit 0 # Program terminated normally</lang>
exit 0 # Program terminated normally</lang>

=={{header|Unlambda}}==
<lang unlambda>`ei</lang>
Note: the argument to the <code>e</code> function is the return value of the program; however many implementation simply ignore it.

There are no objects to be cleaned up.


=={{header|Ursa}}==
=={{header|Ursa}}==
Line 1,477: Line 1,479:
If problem then Application.Quit
If problem then Application.Quit
'This will stop the application, but will prompt you to save work.</lang>
'This will stop the application, but will prompt you to save work.</lang>
=={{header|Vedit macro language}}==
<lang vedit>if (#99 == 1) { Return } // Exit current macro. Return to calling macro.
if (#99 == 2) { Break_Out() } // Stop all macro execution and return to command mode.
if (#99 == 3) { Exit } // Exit Vedit. Prompt for saving any changed files.
if (#99 == 4) { Exit(4) } // As above, but return specified value (instead of 0) to OS
if (#99 == 5) { Xall } // Exit Vedit. Save changed files without prompting.
if (#99 == 6) { Qall } // Exit Vedit. Do not save any files.</lang>
Return or Break_Out() do not perform any cleanup. If needed, cleanup has to be done in the macro before exit.
Special ''locked-in macro'' can be used to perform cleanup in case user presses Break key.

When exit from Vedit is done, all the cleanup is performed automatically.
Note, however, that if ''Edit Restore'' is enabled or a ''project'' is open, the session state is saved.
In this case, if your macro does not do cleanup, you may eventually run out of free text registers, and you have to do manual cleanup.


=={{header|VBScript}}==
=={{header|VBScript}}==
Line 1,504: Line 1,493:
next
next
loop</lang>
loop</lang>

=={{header|Vedit macro language}}==
<lang vedit>if (#99 == 1) { Return } // Exit current macro. Return to calling macro.
if (#99 == 2) { Break_Out() } // Stop all macro execution and return to command mode.
if (#99 == 3) { Exit } // Exit Vedit. Prompt for saving any changed files.
if (#99 == 4) { Exit(4) } // As above, but return specified value (instead of 0) to OS
if (#99 == 5) { Xall } // Exit Vedit. Save changed files without prompting.
if (#99 == 6) { Qall } // Exit Vedit. Do not save any files.</lang>
Return or Break_Out() do not perform any cleanup. If needed, cleanup has to be done in the macro before exit.
Special ''locked-in macro'' can be used to perform cleanup in case user presses Break key.

When exit from Vedit is done, all the cleanup is performed automatically.
Note, however, that if ''Edit Restore'' is enabled or a ''project'' is open, the session state is saved.
In this case, if your macro does not do cleanup, you may eventually run out of free text registers, and you have to do manual cleanup.


=={{header|Visual Basic}}==
=={{header|Visual Basic}}==