Error handling types
An exception type for representing Unicode encoding errors.
DecodeError :: String -> (Maybe Word8) -> UnicodeException
(Maybe Word8)Could not decode a byte sequence because it was invalid under
the given encoding, or ran out of input in mid-decode.
EncodeError :: String -> (Maybe Char) -> UnicodeException
This constructor is never used, and will be removed.
(Maybe Char)Tried to encode a character that could not be represented
under the given encoding, or ran out of input in mid-encode.
type OnError a b = String -> Maybe a -> Maybe b
Function type for handling a coding error. It is supplied with
two inputs:
If the handler returns a value wrapped with Just, that value will
be used in the output as the replacement for the invalid input. If
it returns Nothing, no value will be used in the output.
Should the handler need to abort processing, it should use error
or throw an exception (preferably a UnicodeException). It may
use the description provided to construct a more helpful error
report.
A handler for a decoding error.
This exception is never used in practice, and will be removed.
A handler for an encoding error.
Useful error handling functions
Replace an invalid input byte with the Unicode replacement
character U+FFFD.
Throw a UnicodeException if decoding fails.
This function always throws an exception, and will be removed.
Throw a UnicodeException if encoding fails.
ignore :: OnError a b
Ignore an invalid input, substituting nothing in the output.
replace :: b -> OnError a b
Replace an invalid input with a valid output.
Instances
4
instance Eq UnicodeExceptioninstance Show UnicodeExceptioninstance Exception UnicodeExceptioninstance NFData UnicodeException
- Copyright
- (c) Bryan O'Sullivan 2009