System.Exit (original) (raw)
Description
Exiting the program.
Synopsis
- data ExitCode
- exitWith :: ExitCode -> IO a
- exitFailure :: IO a
- exitSuccess :: IO a
Documentation
data ExitCode Source
Defines the exit codes that a program can return.
Constructors
ExitSuccess | indicates successful termination; |
---|---|
ExitFailure Int | indicates program failure with an exit code. The exact interpretation of the code is operating-system dependent. In particular, some values may be prohibited (e.g. 0 on a POSIX-compliant system). |
exitWith :: ExitCode -> IO aSource
Computation [exitWith](System-Exit.html#v:exitWith)
code
throws [ExitCode](System-Exit.html#t:ExitCode)
code
. Normally this terminates the program, returning code
to the program's caller.
On program termination, the standard Handle
s stdout
andstderr
are flushed automatically; any other buffered Handle
s need to be flushed manually, otherwise the buffered data will be discarded.
A program that fails in any other way is treated as if it had called [exitFailure](System-Exit.html#v:exitFailure)
. A program that terminates successfully without calling [exitWith](System-Exit.html#v:exitWith)
explicitly is treated as it it had called [exitWith](System-Exit.html#v:exitWith)
[ExitSuccess](System-Exit.html#v:ExitSuccess)
.
As an [ExitCode](System-Exit.html#t:ExitCode)
is not an [IOError](System-IO-Error.html#t:IOError)
, [exitWith](System-Exit.html#v:exitWith)
bypasses the error handling in the [IO](System-IO.html#t:IO)
monad and cannot be intercepted bycatch
from the Prelude. However it is a SomeException
, and can be caught using the functions of Control.Exception. This means that cleanup computations added with [bracket](Control-Exception.html#t:bracket)
(from Control.Exception) are also executed properly on [exitWith](System-Exit.html#v:exitWith)
.
Note: in GHC, [exitWith](System-Exit.html#v:exitWith)
should be called from the main program thread in order to exit the process. When called from another thread, [exitWith](System-Exit.html#v:exitWith)
will throw an ExitException
as normal, but the exception will not cause the process itself to exit.