LIB/GTK: improve exceptions/error handling

This commit is contained in:
2016-04-11 01:59:18 +02:00
parent 3f303b4cd4
commit c2f3da6180
5 changed files with 68 additions and 32 deletions

View File

@@ -16,6 +16,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_HADDOCK ignore-exports #-}
module HSFM.GUI.Gtk.Callbacks where

View File

@@ -24,14 +24,17 @@ module HSFM.GUI.Gtk.Dialogs where
import Control.Exception
(
catch
, displayException
, throw
, try
, SomeException
, IOException
, catches
, Handler(..)
)
import Control.Monad
(
forM
, when
, void
)
import Data.Version
(
@@ -209,11 +212,13 @@ withConfirmationDialog str io = do
-- |Execute the given IO action. If the action throws exceptions,
-- visualize them via 'showErrorDialog'.
withErrorDialog :: IO a -> IO ()
withErrorDialog io = do
r <- try io
either (\e -> showErrorDialog $ show (e :: SomeException))
(\_ -> return ())
r
withErrorDialog io =
catches (void io)
[ Handler (\e -> showErrorDialog
$ displayException (e :: IOException))
, Handler (\e -> showErrorDialog
$ displayException (e :: FmIOException))
]
-- |Asks the user which directory copy mode he wants via dialog popup