[Haskell-beginners] Better error messages

Daniel Fischer daniel.is.fischer at googlemail.com
Thu Dec 29 21:42:59 CET 2011


On Thursday 29 December 2011, 21:25:31, Peter Hall wrote:
> If I have something like this
> 
> main = do
>     args <- getArgs
>     let file = args !! 0
>     -- etc...
> 
> 
> And I run it without any arguments, I get an error message like this:
> "Prelude.(!!): index too large".
> 
> What's the best way to handle an error like this to give a better
> message back to the user?

main = do
    args <- getArgs
    case args of
      [] -> complain
      _ -> happiness

or

    args <- getArgs
    if null args
      then complain
      else happiness



More information about the Beginners mailing list