diff options
author | Sibi Prabakaran <sibi@psibi.in> | 2020-05-02 18:37:58 +0530 |
---|---|---|
committer | jao <jao@gnu.org> | 2020-05-02 16:34:52 +0100 |
commit | 68ac4d3ae6f37a2f73109f65f67e0b0d209696f0 (patch) | |
tree | 490ebb9a927ec26c2ca8eb6bb707ad2217f8f271 /src/Xmobar/System/Utils.hs | |
parent | b7a3d674581720bfb63bf73cae8368ebbad81004 (diff) | |
download | xmobar-68ac4d3ae6f37a2f73109f65f67e0b0d209696f0.tar.gz xmobar-68ac4d3ae6f37a2f73109f65f67e0b0d209696f0.tar.bz2 |
Update stderr and the bar on receiving exception
Diffstat (limited to 'src/Xmobar/System/Utils.hs')
-rw-r--r-- | src/Xmobar/System/Utils.hs | 13 |
1 files changed, 12 insertions, 1 deletions
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) + |