<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.E-mailStijl17
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.E-mailStijl18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=NL link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span lang=EN-US>Hi all,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>The program reads lots of small Text files. readCDFile handles the encoding. Below is the simplest version of readCDFile.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>If I call readCDFile "/home/kees/freeDB/inputError/" "blah" (the file blah does not exist) I get:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>Left "MyError: /home/kees/freeDB/inputError/blah: openBinaryFile: does not exist (No such file or directory)". The exception is caught by exceptionHandler<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>If I call readCDFile "/home/kees/freeDB/inputError/" "67129209" I get freeDB: Cannot decode byte '\xa0': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream. The exception is not caught by exceptionHandler (No “MyError: ” in front). The file 67129209 is indeed bad encoded.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>I’am using SomeException. Still, this ‘bad encoding exception’ is not caught. Why?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Kees<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>import</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>qualified</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> Data.Text </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>as</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> T<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>import</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> System.FilePath.Posix<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>import</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>qualified</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> Data.Text.Encoding </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>as</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> TE<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>import</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>qualified</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> Data.ByteString.Lazy </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>as</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> B<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>import</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> Prelude </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>hiding</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> (</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-fareast-language:NL'>catch</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>)<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>import</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> Control.Exception<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'><o:p> </o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-fareast-language:NL'>main</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>::</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>IO</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> ()<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>main = </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#C586C0;mso-fareast-language:NL'>do</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'><o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>          res <- readCDFile </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-fareast-language:NL'>"/home/kees/freeDB/inputError/"</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-fareast-language:NL'>"67129209"</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> <o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>          print res<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'><o:p> </o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-fareast-language:NL'>readCDFile</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>::</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>FilePath</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>-></span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>FilePath</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>-></span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>IO</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> (</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>Either</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>String</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>T</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>.</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>Text</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>)<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>readCDFile baseDir fn = </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#C586C0;mso-fareast-language:NL'>do</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'><o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>  catch ( </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#C586C0;mso-fareast-language:NL'>do</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> <o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>            buffer <- B.readFile (combine baseDir fn)<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>            </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>let</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> bufferStrict = B.toStrict buffer<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>            return $ Right $ TE.decodeUtf8 bufferStrict<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>         ) exceptionHandler<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'><o:p> </o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-fareast-language:NL'>exceptionHandler</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>::</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>SomeException</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>-></span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>IO</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> (</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>Either</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>String</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>T</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>.</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>Text</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>)<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>exceptionHandler e = </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#C586C0;mso-fareast-language:NL'>do</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> </span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-fareast-language:NL'>let</span><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> err = show e<o:p></o:p></span></p><p class=MsoNormal style='line-height:14.25pt;background:#1E1E1E'><span lang=EN-US style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>                        </span><span style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'>return $ Left $ </span><span style='font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-fareast-language:NL'>"MyError: "</span><span style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'> ++ err<o:p></o:p></span></p><p class=MsoNormal style='margin-bottom:12.0pt;line-height:14.25pt;background:#1E1E1E'><span style='font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-fareast-language:NL'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br /> <table style="border-top: 1px solid #D3D4DE;">
        <tr>
      <td style="width: 55px; padding-top: 18px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
                <td style="width: 470px; padding-top: 17px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virusvrij. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>                </td>
        </tr>
</table>
<a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body></html>