Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between error and fail?

I've been looking for answer for this question and found this blog post. It says that fail has advantages over error because it isn't constrained to the IO monad.

Should i use fail instead of error all over my code? Does fail raise Control.Exception.catchable exceptions in IO?

EDIT: I've found an update for the link above.

like image 959
arrowd Avatar asked Dec 14 '12 12:12

arrowd


People also ask

What is the difference between fail and error?

Both failure and error in JUnit tests indicate an undesired situation, but their semantics are different. Failures notify of an invalid test result, errors indicate an unexpected test execution. Also, please check out the example code at GitHub.

What is difference between error and mistake?

Mistakes are an accident. You know it's wrong, but the wrong word slips out. An error, on the other hand, is something you don't know. It's grammar you haven't learned yet or vocabulary you haven't learned the nuance of yet.

What is an error in testing?

Testing is the process of identifying defects, where a defect is any variance between actual and expected results. “A mistake in coding is called Error, error found by tester is called Defect, defect accepted by development team then it is called Bug, build does not meet the requirements then it Is Failure.”

What is the difference between flaw and error?

An error is a mistake. If the mistake reaches the user, it is a fault. The fault is the cause of a failure. It's called defect if it's found during development time, bug when it's found while testing and failure when the user finds it.


1 Answers

Here's my advice:

  • If you're in IO code already, use proper exceptions via throwIO from Control.Exception.

  • If your code uses a monad stack already, add errors to your monad stack if it doesn't support it already, and use those.

  • If you are in non-monadic code, write total functions. I.e., avoid error and incomplete patterns if you can. Using fail here would only force your code to be unnecessarily monadic. If you need exceptional results, use a proper data type (such as Maybe or Either or a custom datatype).

like image 138
kosmikus Avatar answered Sep 29 '22 22:09

kosmikus