
27 Aug
2008
27 Aug
'08
5:01 p.m.
--- On Wed, 8/27/08, Dan Weston
Failure to handle a null pointer is just like using fromJust and results in the same program termination (undefined).
Dan
Well, not (IMHO) 'just like': 'fromJust Nothing' turns into a 'catchable' exception in the IO Monad, but a SEGFAULT certainly doesn't. E.g.
import Control.Exception as C import Data.Maybe main = do (fromJust Nothing >>= ( \ s -> putStrLn s)) `C.catch` (\ _ -> putStrLn "ok")
prints 'ok', whereas:
import Foreign.Ptr import Foreign.Storable import qualified Control.Exception as E main = poke nullPtr '\0' `E.catch` (\ _ -> putStrLn "ok")
just segfaults...