> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/perl6-rosettacode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/perl6-rosettacode/programming_tasks/p/program_termination.md).

# Program termination

```perl
if $problem { exit $error-code }
```

An `exit` runs all appropriate scope-leaving blocks such as `LEAVE`, `KEEP`, or `UNDO`, followed by all `END` 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. (Raku does not yet have a thread-termination policy, but will need to before we're done.)
