Personal tools

Exception

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(explanation)
 
(Control.Monad.Error)
Line 3: Line 3:
 
Since exceptions must be expected at runtime there are also mechanisms for (selectively) handling them.
 
Since exceptions must be expected at runtime there are also mechanisms for (selectively) handling them.
 
(<hask>Control.Exception,try</hask>, <hask>Control.Exception.catch</hask>)
 
(<hask>Control.Exception,try</hask>, <hask>Control.Exception.catch</hask>)
Unfortunately the Haskell library names common exceptions of IO actions <hask>IOError</hask>.
+
Unfortunately Haskell's standard library names common exceptions of IO actions <hask>IOError</hask>
  +
and the module <hask>Control.Monad.Error</hask> is about exception handling not error handling.
 
In general you should be very careful, not to mix up exceptions with [[error]]s.
 
In general you should be very careful, not to mix up exceptions with [[error]]s.
 
Actually, an unhandled exception is an [[error]].
 
Actually, an unhandled exception is an [[error]].

Revision as of 19:56, 8 December 2007

An exception denotes an unpredictable situation at runtime, like "out of disk storage", "read protected file", "user removed disk while reading", "syntax error in user input". These are situation which occur relatively seldom and thus their immediate handling would clutter the code which should describe the regular processing. Since exceptions must be expected at runtime there are also mechanisms for (selectively) handling them.

(
Control.Exception,try
,
Control.Exception.catch
) Unfortunately Haskell's standard library names common exceptions of IO actions
IOError
and the module
Control.Monad.Error
is about exception handling not error handling.

In general you should be very careful, not to mix up exceptions with errors. Actually, an unhandled exception is an error.

See also