Error vs. Exception
There is confusion about the distinction of errors and exceptions for a long time, repeated threads in Haskell-Cafe and more and more packages that handle errors and exceptions or something between. Although both terms are related and sometimes hard to distinguish, it is important to do it carefully. This is like the confusion between parallelism and concurrency.
The first problem is that exception seem to me to be the historically younger term. Before there were only errors, independent from whether they are programming or I/O or user errors. In this article we want to use the term "exception" for expected but irregular situations at runtime and the term "error" for mistakes in the running program, that can be resolved only by fixing the program.
The history may have led to the identifiers we find today in the Haskell language and standard Haskell modules.
- Exceptions: ,Prelude.catch,Control.Exception.catch,Control.Exception.try,IOErrorControl.Monad.Error
- Errors: ,error,Control.Exception.catchDebug.Trace.trace
Prelude> catch (error "bla") (\msg -> putStrLn $ "catched " ++ show msg) *** Exception: bla Prelude> Control.Exception.catch (error "bla") (\msg -> putStrLn $ "catched " ++ show (msg::Control.Exception.SomeException)) catched bla
that shall help spotting a programming error.A program should work as well when all
are replaced by infinite loops.However infinite loops in general cannot be catched, whereas calls to sugared functions like
Even more confusion was initiated by Java programming language
to use the term "exceptions" for programming errors like the
and introducing the distinction between
checked and unchecked exceptions.
error handling = debugging
examples: GHC errors and exceptions
Modula-3 arithmetic library
2 When exceptions become errors
3 When errors become exceptions