summaryrefslogtreecommitdiffstats
path: root/XMonad.hs
diff options
context:
space:
mode:
authorDavid Roundy <droundy@darcs.net>2007-06-12 17:42:53 +0200
committerDavid Roundy <droundy@darcs.net>2007-06-12 17:42:53 +0200
commit904b5d31224aaa14fcab522d10de1c6b1d898f68 (patch)
tree1be49bf57f39c52af50a1c14eedcf9a467b005e7 /XMonad.hs
parent8d0355c4281b59e532d6fd7397161a61a58a579b (diff)
downloadmetatile-904b5d31224aaa14fcab522d10de1c6b1d898f68.tar
metatile-904b5d31224aaa14fcab522d10de1c6b1d898f68.zip
add catchX to catch exceptions.
darcs-hash:20070612154253-72aca-b2c7e24b5e70a09feaebccd443aebbe37b568efa
Diffstat (limited to 'XMonad.hs')
-rw-r--r--XMonad.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/XMonad.hs b/XMonad.hs
index b296a38..49c577e 100644
--- a/XMonad.hs
+++ b/XMonad.hs
@@ -17,7 +17,7 @@
module XMonad (
X, WindowSet, WorkspaceId(..), ScreenId(..), XState(..), XConf(..), Layout(..),
Typeable, Message, SomeMessage(..), fromMessage, runLayout,
- runX, io, catchIO, withDisplay, withWindowSet, isRoot, spawn, restart, trace, whenJust, whenX,
+ runX, catchX, io, catchIO, withDisplay, withWindowSet, isRoot, spawn, restart, trace, whenJust, whenX,
atom_WM_STATE, atom_WM_PROTOCOLS, atom_WM_DELETE_WINDOW
) where
@@ -76,6 +76,17 @@ newtype X a = X (ReaderT XConf (StateT XState IO) a)
runX :: XConf -> XState -> X a -> IO ()
runX c st (X a) = runStateT (runReaderT a c) st >> return ()
+-- | Run in the X monad, and in case of exception, and catch it and log it
+-- to stderr, and run the error case.
+catchX :: X a -> X a -> X a
+catchX (X job) (X errcase) =
+ do st <- get
+ c <- ask
+ (a,s') <- io ((runStateT (runReaderT job c) st) `catch`
+ \e -> (do hPutStrLn stderr (show e); runStateT (runReaderT errcase c) st))
+ put s'
+ return a
+
-- ---------------------------------------------------------------------
-- Convenient wrappers to state