{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module CheckedIO.Exception (
  Exception (..),
  mapExceptionM,
  liftE,

  -- * Synchronous exceptions
  throw,
  catch,
  try,

  -- * Asynchronous exceptions
  throwTo,

  -- * Imprecise exceptions
  throwImprecise,

  -- * Converting exceptions
  ConvertException (..),
  convertE,

  -- * Exception supertypes
  AnyException (..),
  SomeSyncException (..),
  SomeException (..),
  SomeAsyncException (..),
) where

import Control.Exception (
  Exception (..),
  SomeAsyncException (..),
  SomeException (..),
 )

import CheckedIO.Core
import CheckedIO.Prelude.NoIO

-- | A type class for converting one exception type to another.
class (Exception e1, Exception e2) => ConvertException e1 e2 where
  convertException :: e1 -> e2

instance {-# OVERLAPPABLE #-} Exception e => ConvertException e e where
  convertException :: e -> e
convertException = e -> e
forall a. a -> a
id

convertE :: ConvertException e1 e2 => IOE e1 a -> IOE e2 a
convertE :: forall e1 e2 a. ConvertException e1 e2 => IOE e1 a -> IOE e2 a
convertE = (e1 -> e2) -> IOE e1 a -> IOE e2 a
forall e1 e2 (m1 :: * -> *) (m2 :: * -> *) a.
(MonadCatchIO e1 m1, MonadRunAsIOE e2 m2) =>
(e1 -> e2) -> m1 a -> m2 a
mapExceptionM e1 -> e2
forall e1 e2. ConvertException e1 e2 => e1 -> e2
convertException