[Haskell-beginners] better exception handling

Miro Karpis miroslav.karpis at gmail.com
Wed Oct 23 21:11:32 UTC 2013


Please, can you help me with following?... I have a working code but am not
very happy with the error handling in "updateStocks" function. It does what
it should, but I would like to implement some kind of guards. Problem is
that it always ends it some error + am not sure if I can use guards in
inside defined variable. Pls. what would you suggest?



httpExceptionHandler ::  HttpException -> IO L.ByteString
httpExceptionHandler e = (putStrLn "Error: simpleHttp returned exception ")
>> (return L.empty)

getStocks :: String -> IO L.ByteString
getStocks url = (simpleHttp url) `X.catch` httpExceptionHandler

updateStocks :: IO String
updateStocks = do
  yqlResult <- getStocks testQuery
  case yqlResult of x | x == L.empty -> return "return exception"
                               | otherwise    -> return "here I will call
another function"

thanks,
m.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131023/f808cadc/attachment.html>


More information about the Beginners mailing list