From fad44f14900d5802d02c0c924205870e910e96ae Mon Sep 17 00:00:00 2001 From: simonmar Date: Mon, 10 Apr 2000 13:35:45 +0000 Subject: [PATCH] [project @ 2000-04-10 13:35:45 by simonmar] Add Array exceptions (out-of-bounds and undefined element), not used yet. --- ghc/lib/std/PrelException.lhs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ghc/lib/std/PrelException.lhs b/ghc/lib/std/PrelException.lhs index 1f317aa..a04c66a 100644 --- a/ghc/lib/std/PrelException.lhs +++ b/ghc/lib/std/PrelException.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelException.lhs,v 1.15 2000/04/10 13:18:13 simonpj Exp $ +% $Id: PrelException.lhs,v 1.16 2000/04/10 13:35:45 simonmar Exp $ % % (c) The GRAP/AQUA Project, Glasgow University, 1998 % @@ -12,6 +12,7 @@ Exceptions and exception-handling functions. #ifndef __HUGS__ module PrelException where +import PrelList import PrelBase import PrelMaybe import PrelShow @@ -32,6 +33,7 @@ import PrelGHC data Exception = IOException IOError -- IO exceptions (from 'ioError') | ArithException ArithException -- Arithmetic exceptions + | ArrayException ArrayException -- Array-related exceptions | ErrorCall String -- Calls to 'error' | NoMethodError String -- A non-existent method was invoked | PatternMatchFail String -- A pattern match failed @@ -60,6 +62,10 @@ data AsyncException | ThreadKilled deriving (Eq, Ord) +data ArrayException + = IndexOutOfBounds String -- out-of-range array access + | UndefinedElement String -- evaluating an undefined element + stackOverflow, heapOverflow :: Exception -- for the RTS stackOverflow = AsyncException StackOverflow heapOverflow = AsyncException HeapOverflow @@ -76,9 +82,20 @@ instance Show AsyncException where showsPrec _ HeapOverflow = showString "heap overflow" showsPrec _ ThreadKilled = showString "thread killed" +instance Show ArrayException where + showsPrec _ (IndexOutOfBounds s) + = showString "array index out of range" + . (if not (null s) then showString ": " . showString s + else id) + showsPrec _ (UndefinedElement s) + = showString "undefined array element" + . (if not (null s) then showString ": " . showString s + else id) + instance Show Exception where showsPrec _ (IOException err) = shows err showsPrec _ (ArithException err) = shows err + showsPrec _ (ArrayException err) = shows err showsPrec _ (ErrorCall err) = showString err showsPrec _ (NoMethodError err) = showString err showsPrec _ (PatternMatchFail err) = showString err @@ -94,7 +111,6 @@ instance Show Exception where showsPrec _ (NonTermination) = showString "<>" \end{code} - %********************************************************* %* * \subsection{Primitive catch and throw} -- 1.7.10.4