@@ -137,9 +137,14 @@ import System.Timeout (timeout)
137137import Control.Monad (when)
138138import Control.Monad.Reader (ask)
139139import Control.Monad.IO.Class (liftIO)
140−import Control.Applicative ((<$>))
141−import Control.Exception (Exception(..), throw, throwIO, SomeException)
142−import qualified Control.Exception as Ex (catch, mask, mask_, try)
140+import Control.Monad.Catch
141+ ( Exception
142+ , SomeException
143+ , throwM
144+ , fromException
145+ )
146+import qualified Control.Monad.Catch as Catch
147+import Control.Applicative
143148import Control.Distributed.Process.Internal.StrictMVar
144149 ( StrictMVar
145150 , modifyMVar
@@ -203,7 +208,6 @@ import Control.Distributed.Process.Internal.Types
203208 , isEncoded
204209 , createMessage
205210 , createUnencodedMessage
206− , runLocalProcess
207211 , ImplicitReconnect( NoImplicitReconnect)
208212 , LocalProcessState
209213 , LocalSendPortId
@@ -227,6 +231,7 @@ import Control.Distributed.Process.Internal.WeakTQueue
227231 , readTQueue
228232 , mkWeakTQueue
229233 )
234+import Prelude
230235
231236import Unsafe.Coerce
232237
@@ -699,7 +704,7 @@ instance Exception ProcessTerminationException
699704
700705-- | Terminate immediately (throws a ProcessTerminationException)
701706terminate :: Process a
702−terminate = liftIO $ throwIO ProcessTerminationException
707+terminate = throwM ProcessTerminationException
703708
704709-- [Issue #110]
705710-- | Die immediately - throws a 'ProcessExitException' with the given @reason@.
@@ -709,7 +714,7 @@ die reason = do
709714-- could be decoded by a handler passed to 'catchExit', re-thrown or even
710715-- passed to another process via the tracing mechanism.
711716 pid <- getSelfPid
712− liftIO $ throwIO (ProcessExitException pid (createMessage reason))
717+ throwM (ProcessExitException pid (createMessage reason))
713718
714719-- | Forceful request to kill a process. Where 'exit' provides an exception
715720-- that can be caught and handled, 'kill' throws an unexposed exception type
@@ -742,12 +747,12 @@ catchExit :: forall a b . (Show a, Serializable a)
742747 => Process b
743748 -> (ProcessId -> a -> Process b)
744749 -> Process b
745−catchExit act exitHandler = catch act handleExit
750+catchExit act exitHandler = Catch.catch act handleExit
746751 where
747752 handleExit ex@(ProcessExitException from msg) =
748753 if messageFingerprint msg == fingerprint (undefined :: a)
749754 then exitHandler from decoded
750− else liftIO $ throwIO ex
755+ else throwM ex
751756 where
752757 decoded :: a
753758 -- Make sure the value is fully decoded so that we don't hang to
@@ -766,12 +771,12 @@ catchExit act exitHandler = catch act handleExit
766771catchesExit :: Process b
767772 -> [(ProcessId -> Message -> (Process (Maybe b)))]
768773 -> Process b
769−catchesExit act handlers = catch act ((flip handleExit) handlers)
774+catchesExit act handlers = Catch.catch act ((flip handleExit) handlers)
770775 where
771776 handleExit :: ProcessExitException
772777 -> [(ProcessId -> Message -> Process (Maybe b))]
773778 -> Process b
774− handleExit ex [] = liftIO $ throwIO ex
779+ handleExit ex [] = throwM ex
775780 handleExit ex@(ProcessExitException from msg) (h:hs) = do
776781 r <- h from msg
777782 case r of
@@ -936,56 +941,43 @@ unmonitor ref = do
936941
937942-- | Lift 'Control.Exception.catch'
938943catch :: 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)
944+catch = Catch.catch
945+{-# DEPRECATED catch "Use Control.Monad.Catch.catch instead" #-}
942946
943947-- | Lift 'Control.Exception.try'
944948try :: Exception e => Process a -> Process (Either e a)
945−try p = do
946− lproc <- ask
947− liftIO $ Ex.try (runLocalProcess lproc p)
949+try = Catch.try
950+{-# DEPRECATED try "Use Control.Monad.Catch.mask_ instead" #-}
948951
949952-- | Lift 'Control.Exception.mask'
950953mask :: ((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
954+mask = Catch.mask
955+{-# DEPRECATED mask "Use Control.Monad.Catch.mask_ instead" #-}
961956
962957-- | Lift 'Control.Exception.mask_'
963958mask_ :: Process a -> Process a
964−mask_ p = do
965− lproc <- ask
966− liftIO $ Ex.mask_ $ runLocalProcess lproc p
959+mask_ = Catch.mask_
960+{-# DEPRECATED mask_ "Use Control.Monad.Catch.mask_ instead" #-}
967961
968962-- | Lift 'Control.Exception.onException'
969963onException :: Process a -> Process b -> Process a
970−onException p what = p `catch` \e -> do _ <- what
971− liftIO $ throwIO (e :: SomeException)
964+onException = Catch.onException
965+{-# DEPRECATED onException "Use Control.Monad.Catch.onException instead" #-}
972966
973967-- | Lift 'Control.Exception.bracket'
974968bracket :: 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
969+bracket = Catch.bracket
970+{-# DEPRECATED bracket "Use Control.Monad.Catch.bracket instead" #-}
981971
982972-- | Lift 'Control.Exception.bracket_'
983973bracket_ :: Process a -> Process b -> Process c -> Process c
984−bracket_ before after thing = bracket before (const after) (const thing)
974+bracket_ = Catch.bracket_
975+{-# DEPRECATED bracket_ "Use Control.Monad.Catch.bracket_ instead" #-}
985976
986977-- | Lift 'Control.Exception.finally'
987978finally :: Process a -> Process b -> Process a
988−finally a sequel = bracket_ (return ()) sequel a
979+finally = Catch.finally
980+{-# DEPRECATED finally "Use Control.Monad.Catch.finally instead" #-}
989981
990982-- | You need this when using 'catches'
991983data Handler a = forall e . Exception e => Handler (e -> Process a)
@@ -995,10 +987,10 @@ instance Functor Handler where
995987
996988-- | Lift 'Control.Exception.catches'
997989catches :: Process a -> [Handler a] -> Process a
998−catches proc handlers = proc `catch` catchesHandler handlers
990+catches proc handlers = proc `Catch.catch` catchesHandler handlers
999991
1000992catchesHandler :: [Handler a] -> SomeException -> Process a
1001−catchesHandler handlers e = foldr tryHandler (throw e) handlers
993+catchesHandler handlers e = foldr tryHandler (throwM e) handlers
1002994 where tryHandler (Handler handler) res
1003995 = case fromException e of
1004996 Just e' -> handler e'
@@ -1138,7 +1130,7 @@ unregister label = do
11381130handleRegistrationReply :: String -> Bool -> Maybe ProcessId -> Process ()
11391131handleRegistrationReply label ok owner =
11401132 when (not ok) $
1141− liftIO $ throwIO $ ProcessRegistrationException label owner
1133+ throwM $ ProcessRegistrationException label owner
11421134
11431135-- | Remove a process from a remote registry (asynchronous).
11441136--