From 68ac4d3ae6f37a2f73109f65f67e0b0d209696f0 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sat, 2 May 2020 18:37:58 +0530 Subject: Update stderr and the bar on receiving exception --- src/Xmobar/System/Utils.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/Xmobar/System') diff --git a/src/Xmobar/System/Utils.hs b/src/Xmobar/System/Utils.hs index 636436b..59c485c 100644 --- a/src/Xmobar/System/Utils.hs +++ b/src/Xmobar/System/Utils.hs @@ -17,7 +17,7 @@ ------------------------------------------------------------------------------ -module Xmobar.System.Utils (expandHome, changeLoop) +module Xmobar.System.Utils (expandHome, changeLoop, onSomeException) where import Control.Monad @@ -25,6 +25,7 @@ import Control.Concurrent.STM import System.Environment import System.FilePath +import Control.Exception expandHome :: FilePath -> IO FilePath expandHome ('~':'/':path) = fmap ( path) (getEnv "HOME") @@ -39,3 +40,13 @@ changeLoop s f = atomically s >>= go new <- s guard (new /= old) return new) + +-- | Like 'finally', but only performs the final action if there was an +-- exception raised by the computation. +-- +-- Note that this implementation is a slight modification of +-- onException function. +onSomeException :: IO a -> (SomeException -> IO b) -> IO a +onSomeException io what = io `catch` \e -> do _ <- what e + throwIO (e :: SomeException) + -- cgit v1.2.3