@@ -264,6 +264,10 @@ fork :: Settings
264264 -> InternalInfo0
265265 -> IO ()
266266fork set mkConn addr app counter ii0 = settingsFork set $ \ unmask ->
267+ -- Call the user-supplied on exception code if any
268+ -- exceptions are thrown.
269+ handle (settingsOnException set Nothing) .
270+
267271 -- Allocate a new IORef indicating whether the connection has been
268272 -- closed, to avoid double-freeing a connection
269273 withClosedRef $ \ref ->
@@ -292,10 +296,6 @@ fork set mkConn addr app counter ii0 = settingsFork set $ \ unmask ->
292296 -- in the case of all exceptions, so it is safe to one
293297 -- again allow async exceptions.
294298 in unmask .
295− -- Call the user-supplied on exception code if any
296− -- exceptions are thrown.
297− handle (settingsOnException set Nothing) .
298−
299299 -- Call the user-supplied code for connection open and close events
300300 bracket (onOpen addr) (onClose addr) $ \goingon ->
301301