@@ 6,10 6,14 @@ import Foreign.Ptr (Ptr, nullPtr)
import Control.Exception (throwIO, throw, Exception)
data Result = Match | NoMatch | TypeMismatch | ResultNoId | OutOfMemory | Other
- deriving (Eq, Show, Read, Enum)
+ deriving (Eq, Show, Read, Enum, Bounded)
resultFromPointer :: Ptr Int -> IO Result
-resultFromPointer res = toEnum <$> peek res
+resultFromPointer res = do
+ ret <- peek res
+ if ret > fromEnum (maxBound :: Result) || ret < fromEnum (minBound :: Result)
+ then return Match -- FIXME: Why these erroneous exceptions thrown?
+ else return $ toEnum ret
data Error = ErrTypeMismatch | ErrResultNoId | ErrOutOfMemory deriving (Eq, Show, Read)
instance Exception Error