@@ -137,9 +137,8 @@ import System.Timeout (timeout)
137137import Control.Monad (when)
138138import Control.Monad.Reader (ask)
139139import Control.Monad.IO.Class (liftIO)
140+import Control.Monad.Catch hiding (Handler, catches)
140141import Control.Applicative ((<$>))
141−import Control.Exception (Exception(..), throw, throwIO, SomeException)
142−import qualified Control.Exception as Ex (catch, mask, mask_, try)
143142import Control.Distributed.Process.Internal.StrictMVar
144143 ( StrictMVar
145144 , modifyMVar
@@ -699,7 +698,7 @@ instance Exception ProcessTerminationException
699698
700699-- | Terminate immediately (throws a ProcessTerminationException)
701700terminate :: Process a
702−terminate = liftIO $ throwIO ProcessTerminationException
701+terminate = throwM ProcessTerminationException
703702
704703-- [Issue #110]
705704-- | Die immediately - throws a 'ProcessExitException' with the given @reason@.
@@ -709,7 +708,7 @@ die reason = do
709708-- could be decoded by a handler passed to 'catchExit', re-thrown or even
710709-- passed to another process via the tracing mechanism.
711710 pid <- getSelfPid
712− liftIO $ throwIO (ProcessExitException pid (createMessage reason))
711+ throwM (ProcessExitException pid (createMessage reason))
713712
714713-- | Forceful request to kill a process. Where 'exit' provides an exception
715714-- that can be caught and handled, 'kill' throws an unexposed exception type
@@ -747,7 +746,7 @@ catchExit act exitHandler = catch act handleExit
747746 handleExit ex@(ProcessExitException from msg) =
748747 if messageFingerprint msg == fingerprint (undefined :: a)
749748 then exitHandler from decoded
750− else liftIO $ throwIO ex
749+ else throwM ex
751750 where
752751 decoded :: a
753752 -- Make sure the value is fully decoded so that we don't hang to
@@ -771,7 +770,7 @@ catchesExit act handlers = catch act ((flip handleExit) handlers)
771770 handleExit :: ProcessExitException
772771 -> [(ProcessId -> Message -> Process (Maybe b))]
773772 -> Process b
774− handleExit ex [] = liftIO $ throwIO ex
773+ handleExit ex [] = throwM ex
775774 handleExit ex@(ProcessExitException from msg) (h:hs) = do
776775 r <- h from msg
777776 case r of
@@ -934,71 +933,19 @@ unmonitor ref = do
934933-- Exception handling --
935934--------------------------------------------------------------------------------
936935
937−-- | Lift 'Control.Exception.catch'
938−catch :: Exception e => Process a -> (e -> Process a) -> Process a
939−catch p h = do
940− lproc <- ask
941− liftIO $ Ex.catch (runLocalProcess lproc p) (runLocalProcess lproc . h)
942−
943−-- | Lift 'Control.Exception.try'
944−try :: Exception e => Process a -> Process (Either e a)
945−try p = do
946− lproc <- ask
947− liftIO $ Ex.try (runLocalProcess lproc p)
948−
949−-- | Lift 'Control.Exception.mask'
950−mask :: ((forall a. Process a -> Process a) -> Process b) -> Process b
951−mask p = do
952− lproc <- ask
953− liftIO $ Ex.mask $ \restore ->
954− runLocalProcess lproc (p (liftRestore restore))
955− where
956− liftRestore :: (forall a. IO a -> IO a)
957− -> (forall a. Process a -> Process a)
958− liftRestore restoreIO = \p2 -> do
959− ourLocalProc <- ask
960− liftIO $ restoreIO $ runLocalProcess ourLocalProc p2
961−
962−-- | Lift 'Control.Exception.mask_'
963−mask_ :: Process a -> Process a
964−mask_ p = do
965− lproc <- ask
966− liftIO $ Ex.mask_ $ runLocalProcess lproc p
967−
968−-- | Lift 'Control.Exception.onException'
969−onException :: Process a -> Process b -> Process a
970−onException p what = p `catch` \e -> do _ <- what
971− liftIO $ throwIO (e :: SomeException)
972−
973−-- | Lift 'Control.Exception.bracket'
974−bracket :: Process a -> (a -> Process b) -> (a -> Process c) -> Process c
975−bracket before after thing =
976− mask $ \restore -> do
977− a <- before
978− r <- restore (thing a) `onException` after a
979− _ <- after a
980− return r
981−
982−-- | Lift 'Control.Exception.bracket_'
983−bracket_ :: Process a -> Process b -> Process c -> Process c
984−bracket_ before after thing = bracket before (const after) (const thing)
985−
986−-- | Lift 'Control.Exception.finally'
987−finally :: Process a -> Process b -> Process a
988−finally a sequel = bracket_ (return ()) sequel a
989−
990936-- | You need this when using 'catches'
991937data Handler a = forall e . Exception e => Handler (e -> Process a)
992938
993939instance Functor Handler where
994940 fmap f (Handler h) = Handler (fmap f . h)
995941
942+
996943-- | Lift 'Control.Exception.catches'
997944catches :: Process a -> [Handler a] -> Process a
998945catches proc handlers = proc `catch` catchesHandler handlers
999946
1000947catchesHandler :: [Handler a] -> SomeException -> Process a
1001−catchesHandler handlers e = foldr tryHandler (throw e) handlers
948+catchesHandler handlers e = foldr tryHandler (throwM e) handlers
1002949 where tryHandler (Handler handler) res
1003950 = case fromException e of
1004951 Just e' -> handler e'
@@ -1138,7 +1085,7 @@ unregister label = do
11381085handleRegistrationReply :: String -> Bool -> Maybe ProcessId -> Process ()
11391086handleRegistrationReply label ok owner =
11401087 when (not ok) $
1141− liftIO $ throwIO $ ProcessRegistrationException label owner
1088+ throwM $ ProcessRegistrationException label owner
11421089
11431090-- | Remove a process from a remote registry (asynchronous).
11441091--