I need help to understand the usage of the three Haskell functions
Control.Exception.try :: Exception e => IO a -> IO (Either e a)
)
Re: question 3: catch and handle are the same (found through hoogle). The choice of which to use will usually depend on the length of each argument. If the action is shorter, use catch and vice versa. Simple handle example from the documentation:
do handle (\NonTermination -> exitWith (ExitFailure 1)) $ ...
Also, you could conceivably curry the handle function to make a custom handler, which you could then pass around, eg. (adapted from documentation):
let handler = handle (\NonTermination -> exitWith (ExitFailure 1))
Custom error messages:
do
let result = 5 `div` 0
let handler = (\_ -> print "Error") :: IOException -> IO ()
catch (print result) handler