File: Exception.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (44 lines) | stat: -rw-r--r-- 1,217 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Exception where

import Data.Typeable -- for Typeable
import Text.Show     -- for Show
import Data.Maybe    -- for Maybe
import Compiler.Base -- for String
import Data.List     -- for ++
import Compiler.IO   -- for IO

data SomeException = forall e. Exception e => SomeException e

class ({-Typeable e,-} Show e) => Exception e where
--    toException :: e -> SomeException
--    fromException :: SomeException -> Maybe e
    displayException :: e -> String
    displayException e = show e

data IOException = IOException String

instance Show IOException where
    show (IOException s) = "IOException " ++ show s

instance Exception IOException
--    toException e = SomeException e
--    fromException e = Just e

data ArithException

data ArrayExeption


--throw :: forall a e. Exception e => e -> a
foreign import bpcall "Prelude:" throw :: IOException -> b

{-
throwIO :: Exception e => e -> IO a
-}

--catch :: Exception e => IO a -> (e -> IO a) -> IO a
foreign import bpcall "Prelude:" catchRaw :: a -> (IOException -> a) -> a
catch :: IO a -> (IOException -> IO a) -> IO a
catch action handler = IO (\s -> catchRaw (runIO action s) (\e -> runIO (handler e) s))