(
GhcException(..), ghcError, progName,
panic, panic#, assertPanic, trace,
- showGhcException
+ showException, showGhcException, tryMost,
+
+#if __GLASGOW_HASKELL__ <= 408
+ catchJust, ioErrors, throwTo,
+#endif
) where
#include "HsVersions.h"
import FastTypes
import DYNAMIC
-import EXCEPTION
+import qualified EXCEPTION as Exception
import TRACE ( trace )
import UNSAFE_IO ( unsafePerformIO )
\begin{code}
ghcError :: GhcException -> a
-ghcError e = throwDyn e
+ghcError e = Exception.throwDyn e
-- error messages all take the form
--
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
\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)
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}