[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-cafe
Subject: Re: [Haskell-cafe] Teach me to cooperate with IOException
From: Henning Thielemann <lemming () henning-thielemann ! de>
Date: 2024-04-16 10:58:13
Message-ID: 77bd8e5-4b16-bb79-1cd-53e3e9cbb71 () henning-thielemann ! de
[Download RAW message or body]
On Tue, 16 Apr 2024, Folsk Pratima wrote:
> foreign import ccall unsafe "complex.c syscall_that_fails" c_syscall_that_fails
> :: Ptr CInt -> IO CInt
>
> sysCall :: Int -> IO ()
> sysCall i =
> allocaBytes (sizeOf (0 :: CInt)) $ \ptr -> do
> st <- c_syscall_that_fails ptr
> errno <- peekElemOff ptr 0
> case st of
> (-1) -> throwIO $ userError $ "syscall: " ++ show errno
> _ -> return ()
>
> ```
>
> Now, I do not think it is a "user error", it is a real system call
> error that might or might not be already covered by System.IO.Error. In
> my case errno is 2, it is "No such file or directory", so it is covered
> by System.IO.Error and I may just use the library. But my C code may
> call whatever!
Generally I discourage using the exceptions implicit in IO. Exceptions
must be properly handled by the function caller, the caller must know what
exceptions can occur. Thus I prefer using Exception monad transformers
like transformers:Trans.ExceptT or
explicit-exception:Trans.Exception.Synchronous.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic