3c0ecb80c02d3c3a6b254593906071fc7e3d09ab
[packages/old-time.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/base/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
10 --
11 -- Exiting the program.
12 --
13 -----------------------------------------------------------------------------
14
15 module System.Exit
16 (
17 ExitCode(ExitSuccess,ExitFailure)
18 , exitWith -- :: ExitCode -> IO a
19 , exitFailure -- :: IO a
20 ) where
21
22 import Prelude
23
24 #ifdef __GLASGOW_HASKELL__
25 import GHC.IOBase
26 #endif
27
28 #ifdef __HUGS__
29 import Hugs.System
30 #endif
31
32 #ifdef __NHC__
33 import System
34 ( ExitCode(..)
35 , exitWith
36 )
37 #endif
38
39 -- ---------------------------------------------------------------------------
40 -- exitWith
41
42 -- `exitWith code' terminates the program, returning `code' to the
43 -- program's caller. Before it terminates, any open or semi-closed
44 -- handles are first closed.
45
46 #ifdef __GLASGOW_HASKELL__
47 exitWith :: ExitCode -> IO a
48 exitWith ExitSuccess = throw (ExitException ExitSuccess)
49 exitWith code@(ExitFailure n)
50 | n == 0 = ioException (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0" Nothing)
51 | otherwise = throw (ExitException code)
52 #endif /* __GLASGOW_HASKELL__ */
53
54 exitFailure :: IO a
55 exitFailure = exitWith (ExitFailure 1)