New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double-pop error when entering exception handler #139

Closed
barrucadu opened this Issue Oct 21, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@barrucadu
Copy link
Owner

barrucadu commented Oct 21, 2017

Exception handlers are implemented over two places. Firstly, when adding an exception handler:

-- run a subcomputation in an exception-catching context.
ACatching h ma c ->
let a = runCont ma (APopCatching . c)
e exc = runCont (h exc) (APopCatching . c)
threads' = goto a tid (catching e tid (cThreads ctx))
in simple threads' Catching

And secondly when raising an exception:

-- | Propagate an exception upwards, finding the closest handler
-- which can deal with it.
propagate :: SomeException -> ThreadId -> Threads n r -> Maybe (Threads n r)
propagate e tid threads = case M.lookup tid threads >>= go . _handlers of
Just (act, hs) -> Just $ except act hs tid threads
Nothing -> Nothing
where
go [] = Nothing
go (Handler h:hs) = maybe (go hs) (\act -> Just (act, hs)) $ h <$> fromException e

Notice that, in both places, the handler is removed from the stack. This must break nested exception handlers. I think the solution is to remove the APopCatching on line 341 of Internal.hs, changing the case to:

    ACatching h ma c ->
      let a        = runCont ma (APopCatching . c)
          e exc    = runCont (h exc) c
          threads' = goto a tid (catching e tid (cThreads ctx))
      in simple threads' Catching

barrucadu added a commit that referenced this issue Oct 21, 2017

barrucadu added a commit that referenced this issue Oct 25, 2017

@barrucadu barrucadu closed this in a963822 Oct 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment