Created
February 13, 2014 04:58
-
-
Save jonschoning/8969965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE PatternGuards, DeriveDataTypeable #-} | |
module Control.Exception.IOErrors where | |
import Data.Typeable | |
import Control.Exception | |
import System.IO.Error | |
data AlreadyExists = AlreadyExists IOError deriving Typeable | |
instance Show AlreadyExists where | |
show (AlreadyExists e) = show e | |
instance Exception AlreadyExists where | |
toException (AlreadyExists e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isAlreadyExistsError ioe = Just (AlreadyExists ioe) | |
| otherwise = Nothing | |
data DoesNotExist = DoesNotExist IOError deriving Typeable | |
instance Show DoesNotExist where | |
show (DoesNotExist e) = show e | |
instance Exception DoesNotExist where | |
toException (DoesNotExist e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isDoesNotExistError ioe = Just (DoesNotExist ioe) | |
| otherwise = Nothing | |
data AlreadyInUse = AlreadyInUse IOError deriving Typeable | |
instance Show AlreadyInUse where | |
show (AlreadyInUse e) = show e | |
instance Exception AlreadyInUse where | |
toException (AlreadyInUse e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isAlreadyInUseError ioe = Just (AlreadyInUse ioe) | |
| otherwise = Nothing | |
data DeviceFull = DeviceFull IOError deriving Typeable | |
instance Show DeviceFull where | |
show (DeviceFull e) = show e | |
instance Exception DeviceFull where | |
toException (DeviceFull e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isFullError ioe = Just (DeviceFull ioe) | |
| otherwise = Nothing | |
data EndOfFile = EndOfFile IOError deriving Typeable | |
instance Show EndOfFile where | |
show (EndOfFile e) = show e | |
instance Exception EndOfFile where | |
toException (EndOfFile e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isEOFError ioe = Just (EndOfFile ioe) | |
| otherwise = Nothing | |
data IllegalOperation = IllegalOperation IOError deriving Typeable | |
instance Show IllegalOperation where | |
show (IllegalOperation e) = show e | |
instance Exception IllegalOperation where | |
toException (IllegalOperation e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isIllegalOperation ioe = Just (IllegalOperation ioe) | |
| otherwise = Nothing | |
data PermissionError = PermissionError IOError deriving Typeable | |
instance Show PermissionError where | |
show (PermissionError e) = show e | |
instance Exception PermissionError where | |
toException (PermissionError e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isPermissionError ioe = Just (PermissionError ioe) | |
| otherwise = Nothing | |
data UserError = UserError IOError deriving Typeable | |
instance Show UserError where | |
show (UserError e) = show e | |
instance Exception UserError where | |
toException (UserError e) = toException e | |
fromException (SomeException e) | |
| Just ioe <- cast e, | |
isUserError ioe = Just (UserError ioe) | |
| otherwise = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment