From eec7075b464896b3a554631ecf879073c1774f78 Mon Sep 17 00:00:00 2001 From: Tristan Ravitch Date: Wed, 4 Oct 2017 09:48:49 -0700 Subject: [PATCH] Implement catchError in a MonadError instance --- macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs b/macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs index e9eafcb9..001b82a4 100644 --- a/macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs +++ b/macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs @@ -179,6 +179,15 @@ newtype DisM ppc s a = DisM { unDisM :: ET.ExceptT (LocatedError ppc s) (ST s) a -- silently fails). instance (w ~ ArchAddrWidth ppc) => ET.MonadError ([Block ppc s], MM.MemWord w, TranslationError w) (DisM ppc s) where throwError e = DisM (ET.throwError e) + catchError a hdlr = do + r <- liftST $ ET.runExceptT (unDisM a) + case r of + Left l -> do + r' <- liftST $ ET.runExceptT (unDisM (hdlr l)) + case r' of + Left e -> DisM (ET.throwError e) + Right res -> return res + Right res -> return res data TranslationError w = TranslationError { transErrorAddr :: MM.MemSegmentOff w , transErrorReason :: TranslationErrorReason w