Handling Errors (continued)

Gustavo Villavicencio gustavov at ucse.edu.ar
Fri Apr 25 11:34:46 EDT 2003


Before nothing, thanks Axel and Alastair.

Following your suggestions i have constructed another two
solutions:

1- getMem s = catch (do m <- newCString s
                        return m)
                    (\_ -> return nullPtr)
              -- the exception handler could be more elaborated.

2- fpred p | p == nullPtr = True
           | otherwise    = False

   getMem s = throwIf (fpred)
                      (\nullPtr -> "memory out")
                      (do m <- newCString s
                          return m)
in both cases

main = getMem s1 >>= \p1 ->
       getMem s2 >>= \p2 ->
       let p3 = hstrL p2 p1
       in peekCString p3 >>= \s ->
          print s

Which of the three solutions, including those of Alastair,
would be better?. Can one fail and other one not in
some situation?.
Thanks again for your help,
gustavo






More information about the FFI mailing list