Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question pains me because if you use the correct <code>try</code> it should work, but you have failed to provide a minimum example. Instead, I will provide a functional example and leave it to you to determine what is different in your code.</p> <pre><code>{-# LANGUAGE DeriveDataTypeable, ScopedTypeVariables #-} </code></pre> <p>I only needed <code>ScopedTypeVariables</code> because I didn't use an explicitly typed function.</p> <pre><code>import Control.Exception as X import Data.ByteString as B import Data.Typeable import Data.Data </code></pre> <p>Notice I am using the <code>Control.Exception</code> module, and the <code>try</code> function from there. I suspect your <code>try</code> comes from elsewhere.</p> <pre><code>data ParseError = Unexpected | MalformedRequestLine ByteString | MalformedHeader ByteString | MissingHeader ByteString () | UnknownSIPVersion ByteString deriving (Typeable, Show, Eq) instance Exception ParseError parseRequest :: IO Int parseRequest = throw Unexpected </code></pre> <p>For testing, my <code>parseResult</code> just throws something.</p> <pre><code>exceptionHandler :: (ByteString -&gt; IO ()) -&gt; ParseError -&gt; IO () exceptionHandler f p = print p main = do r &lt;- X.try parseRequest case r of Right i -&gt; print i Left (e :: ParseError) -&gt; print ("Caught",e) </code></pre> <p>And the main routine is pretty boring - just a summary of the important parts of your routine. It runs fine:</p> <pre><code>$ ghc so.hs [1 of 1] Compiling Main ( so.hs, so.o ) Linking so ... $ ./so ("Caught",Unexpected) </code></pre> <p>If you modify the exception to a different type you'll see the exception is not caught:</p> <pre><code>parseRequest :: IO Int parseRequest = error "This is a different type, and won't be caught by 'ParseError' handlers." </code></pre> <p>With a result of:</p> <pre><code>$ ./so so: This is a different type, thus not caught by 'ParseError' handlers. </code></pre> <p>If you wish to catch ALL exceptions then you need a type that suffices for that task.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload