1 -----------------------------------------------------------------------------
3 -- Module : System.Exit
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
11 -- Exiting the program.
13 -----------------------------------------------------------------------------
17 ExitCode(ExitSuccess,ExitFailure)
18 , exitWith -- :: ExitCode -> IO a
19 , exitFailure -- :: IO a
20 , exitSuccess -- :: IO a
25 #ifdef __GLASGOW_HASKELL__
42 -- ---------------------------------------------------------------------------
45 -- | Computation 'exitWith' @code@ throws 'ExitException' @code@.
46 -- Normally this terminates the program, returning @code@ to the
47 -- program's caller. Before the program terminates, any open or
48 -- semi-closed handles are first closed.
50 -- A program that fails in any other way is treated as if it had
51 -- called 'exitFailure'.
52 -- A program that terminates successfully without calling 'exitWith'
53 -- explicitly is treated as it it had called 'exitWith' 'ExitSuccess'.
55 -- As an 'ExitException' is not an 'IOError', 'exitWith' bypasses
56 -- the error handling in the 'IO' monad and cannot be intercepted by
57 -- 'catch' from the "Prelude". However it is an 'Exception', and can
58 -- be caught using the functions of "Control.Exception". This means
59 -- that cleanup computations added with 'Control.Exception.bracket'
60 -- (from "Control.Exception") are also executed properly on 'exitWith'.
63 exitWith :: ExitCode -> IO a
64 exitWith ExitSuccess = throwIO ExitSuccess
65 exitWith code@(ExitFailure n)
66 | n /= 0 = throwIO code
67 #ifdef __GLASGOW_HASKELL__
68 | otherwise = ioError (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0" Nothing)
70 #endif /* ! __NHC__ */
72 -- | The computation 'exitFailure' is equivalent to
73 -- 'exitWith' @(@'ExitFailure' /exitfail/@)@,
74 -- where /exitfail/ is implementation-dependent.
76 exitFailure = exitWith (ExitFailure 1)
78 -- | The computation 'exitSuccess' is equivalent to
79 -- 'exitWith' 'ExitSuccess', It terminates the program
82 exitSuccess = exitWith ExitSuccess