[project @ 2001-06-28 14:15:04 by simonmar]
[ghc-base.git] / System / Exit.hs
1 -----------------------------------------------------------------------------
2 -- 
3 -- Module      :  System.Exit
4 -- Copyright   :  (c) The University of Glasgow 2001
5 -- License     :  BSD-style (see the file libraries/core/LICENSE)
6 -- 
7 -- Maintainer  :  libraries@haskell.org
8 -- Stability   :  provisional
9 -- Portability :  portable
10 --
11 -- $Id: Exit.hs,v 1.1 2001/06/28 14:15:04 simonmar Exp $
12 --
13 -- Exiting the program.
14 --
15 -----------------------------------------------------------------------------
16
17 module System.Exit
18     ( 
19       ExitCode(ExitSuccess,ExitFailure)
20     , exitWith      -- :: ExitCode -> IO a
21     , exitFailure   -- :: IO a
22   ) where
23
24 import Prelude
25
26 #ifdef __GLASGOW_HASKELL__
27 import GHC.IOBase
28 #endif
29
30 -- ---------------------------------------------------------------------------
31 -- exitWith
32
33 -- `exitWith code' terminates the program, returning `code' to the
34 -- program's caller.  Before it terminates, any open or semi-closed
35 -- handles are first closed.
36
37 exitWith :: ExitCode -> IO a
38 exitWith ExitSuccess = throw (ExitException ExitSuccess)
39 exitWith code@(ExitFailure n) 
40   | n == 0 = ioException (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0" Nothing)
41   | otherwise = throw (ExitException code)
42
43 exitFailure :: IO a
44 exitFailure = exitWith (ExitFailure 1)