Commit bb764eda authored by simonmar's avatar simonmar
Browse files

[project @ 2005-02-15 12:15:25 by simonmar]

ghc -e 'System.Exit.exitWith (System.Exit.ExitFailure 99)'

should just exit 99, rather than printing out the exception.  Also
while I'm here, make all other exceptions cause 'ghc -e' to exit(1),
which is probably what we want.
parent c435fef8
{-# OPTIONS -#include "Linker.h" #-} {-# OPTIONS -#include "Linker.h" #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- $Id: InteractiveUI.hs,v 1.187 2005/02/04 13:32:28 simonmar Exp $ -- $Id: InteractiveUI.hs,v 1.188 2005/02/15 12:15:25 simonmar Exp $
-- --
-- GHC Interactive User Interface -- GHC Interactive User Interface
-- --
...@@ -58,6 +58,7 @@ import Data.Int ( Int64 ) ...@@ -58,6 +58,7 @@ import Data.Int ( Int64 )
import System.Cmd import System.Cmd
import System.CPUTime import System.CPUTime
import System.Environment import System.Environment
import System.Exit ( exitWith, ExitCode(..) )
import System.Directory import System.Directory
import System.IO import System.IO
import System.IO.Error as IO import System.IO.Error as IO
...@@ -246,7 +247,7 @@ runGHCi paths dflags maybe_expr = do ...@@ -246,7 +247,7 @@ runGHCi paths dflags maybe_expr = do
interactiveLoop is_tty show_prompt interactiveLoop is_tty show_prompt
Just expr -> do Just expr -> do
-- just evaluate the expression we were given -- just evaluate the expression we were given
runCommand expr runCommandEval expr
return () return ()
-- and finally, exit -- and finally, exit
...@@ -356,6 +357,15 @@ readlineLoop = do ...@@ -356,6 +357,15 @@ readlineLoop = do
runCommand :: String -> GHCi Bool runCommand :: String -> GHCi Bool
runCommand c = ghciHandle handler (doCommand c) runCommand c = ghciHandle handler (doCommand c)
-- This version is for the GHC command-line option -e. The only difference
-- from runCommand is that it catches the ExitException exception and
-- exits, rather than printing out the exception.
runCommandEval c = ghciHandle handleEval (doCommand c)
where
handleEval (ExitException code) = io (exitWith code)
handleEval e = do showException e
io (exitWith (ExitFailure 1))
-- This is the exception handler for exceptions generated by the -- This is the exception handler for exceptions generated by the
-- user's code; it normally just prints out the exception. The -- user's code; it normally just prints out the exception. The
-- handler must be recursive, in case showing the exception causes -- handler must be recursive, in case showing the exception causes
...@@ -399,7 +409,7 @@ runStmt stmt ...@@ -399,7 +409,7 @@ runStmt stmt
setGHCiState st{cmstate = new_cmstate} setGHCiState st{cmstate = new_cmstate}
case result of case result of
CmRunFailed -> return [] CmRunFailed -> return []
CmRunException e -> showException e >> return [] CmRunException e -> throw e -- this is caught by runCommand(Eval)
CmRunOk names -> return names CmRunOk names -> return names
-- possibly print the type and revert CAFs after evaluating an expression -- possibly print the type and revert CAFs after evaluating an expression
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment