haskell
Haskell Exception Types
Exception types from Haskell's Control.Exception module and the GHC runtime. Haskell uses an extensible hierarchy rooted at SomeException; any type in the Exception typeclass can be thrown with throwIO and caught with catch or try.
25 codes
references hackage.haskell.org/package/base/docs/Control-Exception.htmlghc.gitlab.haskell.org/ghc/doc/users_guide/runtime_control.html
· All codes 25 codes
- ArithException ArithException Base type for arithmetic exceptions. Constructors are: Overflow, Underflow, LossOfPrecision, DivideByZero, Denormal, and RatioZeroDenominator. Thrown by GHC for floating-point and integer arithmetic errors.
- ArrayException ArrayException Base type for array access exceptions from Data.Array. The two constructors are IndexOutOfBounds (index outside declared bounds) and UndefinedElement (element read before being assigned).
- AssertionFailed AssertionFailed Thrown by the assert function when its boolean condition is False. The assert function is defined in Control.Exception and can be disabled at compile time; it differs from error in that it signals a violated assertion rather than an unrecoverable failure.
- AsyncException AsyncException Base type for asynchronous exceptions delivered by the GHC runtime rather than by explicit throw calls. Constructors include StackOverflow, HeapOverflow, ThreadKilled, and UserInterrupt. Use mask or bracket when handling these safely.
- BlockedIndefinitelyOnMVar BlockedIndefinitelyOnMVar Thrown when a thread is blocked on an MVar operation and the runtime determines that no other thread holds a reference to that MVar, so the block can never be resolved. Indicates a localised deadlock on that specific MVar.
- BlockedIndefinitelyOnSTM BlockedIndefinitelyOnSTM Thrown when a thread is blocked inside an atomically block and the runtime determines that no other thread can commit a transaction that would unblock it. Indicates a deadlock within the STM subsystem.
- Deadlock Deadlock Thrown to the main thread when the GHC runtime detects that all threads are blocked and no further progress is possible. Represents a whole-program deadlock rather than a deadlock on a specific synchronisation primitive.
- DivideByZero DivideByZero An ArithException constructor thrown when integer or floating-point division by zero is detected. For Double and Float, division by zero produces Infinity or NaN; for Integral types (Int, Integer) it throws this exception.
- ErrorCall ErrorCall Thrown by the error and errorWithoutStackTrace functions. The constructor wraps a String message. Catching ErrorCall is the typical way to handle calls to error in pure code.
- HeapOverflow HeapOverflow An AsyncException thrown by the GHC runtime when all available heap memory is exhausted. Increase the heap limit with +RTS -M<size> or profile memory usage with +RTS -hc to identify the allocation source.
- IndexOutOfBounds IndexOutOfBounds An ArrayException constructor thrown when an array is indexed outside its declared bounds. The exception message includes the requested index and the valid range.
- IOException IOException Represents failures from I/O operations, including file-not-found, permission denied, invalid argument, and end-of-file conditions. Also known as IOError. Inspect with ioeGetErrorType or ioeGetFileName for details.
- LossOfPrecision LossOfPrecision An ArithException constructor thrown when a floating-point operation cannot be represented exactly in the target type, causing significant bits to be lost. Rarely raised in practice on typical hardware.
- NoMethodError NoMethodError Thrown at runtime when a typeclass method is invoked on a type that provides no implementation — neither a default nor an instance-specific definition. Indicates that an instance declaration is missing or incomplete.
- NonTermination NonTermination Raised by the GHC runtime in very specific circumstances when a non-terminating computation is detected. In practice this is rarely raised; most infinite loops simply run forever without raising an exception.
- Overflow Overflow An ArithException constructor thrown when an arithmetic result exceeds the range of the target type. Applies to fixed-size integer types such as Int; Integer (arbitrary precision) never overflows.
- PatternMatchFail PatternMatchFail Thrown when a partial function is called with a value it does not match. Common sources are non-exhaustive case expressions, partial lambda patterns, and do-notation pattern bindings where the matched constructor is not the one actually present.
- RatioZeroDenominator RatioZeroDenominator An ArithException constructor thrown when a Ratio value is constructed with a zero denominator. Rational arithmetic in Haskell normalises fractions; constructing p % 0 always raises this exception.
- RecConError RecConError Thrown when a record field is accessed but was not given a value during construction. Occurs when a record is constructed without specifying all fields and the omitted fields have no default values defined.
- SomeException SomeException The root type of the Haskell exception hierarchy. Any value whose type is an instance of Exception can be wrapped in SomeException. Catching SomeException catches all synchronous and many asynchronous exceptions; prefer catching specific types.
- StackOverflow StackOverflow An AsyncException thrown by the GHC runtime when the thread stack size exceeds its limit. Typically caused by infinite recursion or very deep call chains. Increase the limit with +RTS -K<size> or rewrite the algorithm using heap-allocated continuations.
- ThreadKilled ThreadKilled An AsyncException delivered to a thread when killThread or throwTo is called on it. Threads should handle ThreadKilled to perform cleanup; it can be temporarily masked with mask but should eventually be re-raised.
- UndefinedElement UndefinedElement An ArrayException constructor thrown when a mutable array element is read before it has been written. Applies to STArray and IOArray when readArray is called before a corresponding writeArray.
- Underflow Underflow An ArithException constructor thrown when a floating-point result is too small to represent and rounds to zero. Behaviour depends on the floating-point hardware and rounding mode in effect.
- UserInterrupt UserInterrupt An AsyncException raised in the main thread when the user presses Ctrl-C (SIGINT). GHC installs a signal handler that delivers this exception; catch it to perform graceful shutdown before exiting.