X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FPanic.lhs;h=01d1568c78145a5921690c8ee00466092eff703b;hb=bd881529c7dd070b79fc8ad4aa3ac47bc79fbe96;hp=fd6839bdc8dc2c5c7d678600b71b40c02ba5cb4d;hpb=ce9687a5f450014c5596b32de8e8a7b99b6389e8;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/Panic.lhs b/ghc/compiler/utils/Panic.lhs index fd6839b..01d1568 100644 --- a/ghc/compiler/utils/Panic.lhs +++ b/ghc/compiler/utils/Panic.lhs @@ -13,7 +13,11 @@ module Panic ( GhcException(..), ghcError, progName, panic, panic#, assertPanic, trace, - showGhcException + showException, showGhcException, tryMost, + +#if __GLASGOW_HASKELL__ <= 408 + catchJust, ioErrors, throwTo, +#endif ) where #include "HsVersions.h" @@ -22,7 +26,7 @@ import Config import FastTypes import DYNAMIC -import EXCEPTION +import qualified EXCEPTION as Exception import TRACE ( trace ) import UNSAFE_IO ( unsafePerformIO ) @@ -33,7 +37,7 @@ GHC's own exception type. \begin{code} ghcError :: GhcException -> a -ghcError e = throwDyn e +ghcError e = Exception.throwDyn e -- error messages all take the form -- @@ -60,6 +64,12 @@ progName = unsafePerformIO (getProgName) short_usage = "Usage: For basic information, try the `--help' option." +showException :: Exception.Exception -> String +-- Show expected dynamic exceptions specially +showException (Exception.DynException d) | Just e <- fromDynamic d + = show (e::GhcException) +showException other_exn = show other_exn + instance Show GhcException where showsPrec _ e@(ProgramError _) = showGhcException e showsPrec _ e = showString progName . showString ": " . showGhcException e @@ -101,7 +111,7 @@ Panics and asserts. \begin{code} panic :: String -> a -panic x = throwDyn (Panic x) +panic x = Exception.throwDyn (Panic x) -- #-versions because panic can't return an unboxed int, and that's -- what TAG_ is with GHC at the moment. Ugh. (Simon) @@ -112,6 +122,40 @@ panic# s = case (panic s) of () -> _ILIT 0 assertPanic :: String -> Int -> a assertPanic file line = - throw (AssertionFailed + Exception.throw (Exception.AssertionFailed ("ASSERT failed! file " ++ file ++ ", line " ++ show line)) \end{code} + +\begin{code} +-- | tryMost is like try, but passes through Interrupted and Panic +-- exceptions. Used when we want soft failures when reading interface +-- files, for example. + +tryMost :: IO a -> IO (Either Exception.Exception a) +tryMost action = do r <- myTry action; filter r + where + filter (Left e@(Exception.DynException d)) + | Just ghc_ex <- fromDynamic d + = case ghc_ex of + Interrupted -> Exception.throw e + Panic _ -> Exception.throw e + _other -> return (Left e) + filter other + = return other + +#if __GLASGOW_HASKELL__ <= 408 +myTry = Exception.tryAllIO +#else +myTry = Exception.try +#endif +\end{code} + +Compatibility stuff: + +\begin{code} +#if __GLASGOW_HASKELL__ <= 408 +catchJust = Exception.catchIO +ioErrors = Exception.justIoErrors +throwTo = Exception.raiseInThread +#endif +\end{code}