diff options
Diffstat (limited to 'compiler/utils/Panic.hs')
-rw-r--r-- | compiler/utils/Panic.hs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/compiler/utils/Panic.hs b/compiler/utils/Panic.hs index 0a21f251fb..03f095b1a0 100644 --- a/compiler/utils/Panic.hs +++ b/compiler/utils/Panic.hs @@ -20,6 +20,8 @@ module Panic ( panic, sorry, assertPanic, trace, panicDoc, sorryDoc, pgmErrorDoc, + cmdLineError, cmdLineErrorIO, + Exception.Exception(..), showException, safeShowException, try, tryMost, throwTo, @@ -27,6 +29,8 @@ module Panic ( ) where #include "HsVersions.h" +import GhcPrelude + import {-# SOURCE #-} Outputable (SDoc, showSDocUnsafe) import Config @@ -193,8 +197,19 @@ panicDoc x doc = throwGhcException (PprPanic x doc) sorryDoc x doc = throwGhcException (PprSorry x doc) pgmErrorDoc x doc = throwGhcException (PprProgramError x doc) +cmdLineError :: String -> a +cmdLineError = unsafeDupablePerformIO . cmdLineErrorIO + +cmdLineErrorIO :: String -> IO a +cmdLineErrorIO x = do + stack <- ccsToStrings =<< getCurrentCCS x + if null stack + then throwGhcException (CmdLineError x) + else throwGhcException (CmdLineError (x ++ '\n' : renderStack stack)) + + --- | Throw an failed assertion exception for a given filename and line number. +-- | Throw a failed assertion exception for a given filename and line number. assertPanic :: String -> Int -> a assertPanic file line = Exception.throw (Exception.AssertionFailed |