[xmonad] Throwing exceptions from a xmonad-contrib module

Daniel Mlot duplode_1 at yahoo.com.br
Sun Oct 9 23:53:26 CEST 2011

Hi all,

A beginner XMonad hacker question: on reading the sources for the 
CycleSelectedLayouts extension I found one thing to be slightly weird. 
Check the following snippet:

cycleToNext :: (Eq a) => [a] -> a -> Maybe a
cycleToNext lst a = do
     -- not beautiful but simple and readable
     ind <- findIndex (a==) lst
     return $ lst !! if ind == length lst - 1 then 0 else ind+1

-- | If the current layout is in the list, cycle to the next layout. 
--   apply the first layout from list.
cycleThroughLayouts :: [String] -> X ()
cycleThroughLayouts lst = do
     winset <- gets windowset
     let ld = description . S.layout . S.workspace . S.current $ winset
     let newld = fromMaybe (head lst) (cycleToNext lst ld)
     sendMessage $ JumpToLayout newld

If you apply cycleThroughLayouts on an empty list, it will try to take 
the list's head. That doesn't crash xmonad, though, because the 
exception is swallowed by sendMessage. Would throwing an exception 
"needlessly" like that just because it will be caught later on count as 
a bug or is it something not worth bothering about?


More information about the xmonad mailing list