I\'m surprised I couldn\'t find an answer to this anywhere.
I\'m writing a roguelike and I\'m using the ncurses library from hackage, which is a pretty good wrapper arou
You can do this using catch from Control.Exception. Note, however, that you need to be in the IO monad to do this.
import qualified Control.Exception as Exc
divide :: Float -> Float -> Float
divide x 0 = error "Division by 0."
divide x y = x / y
main :: IO ()
main = Exc.catch (print $ divide 5 0) handler
where
handler :: Exc.ErrorCall -> IO ()
handler _ = putStrLn $ "You divided by 0!"