-- tryWrite --------------------------------------------------------------------

-- | evaluate an IO thing, catch any errors, write them to a WriterT

_tryWrite :: IO a -> WriterT [SomeException] IO (Maybe a)
_tryWrite io = do
  io' <- liftIO (try io >>= evaluate)
  case io' of
    Left e  -> tell [e] >> liftIO (return Nothing)
    Right r -> (liftIO . return . Just) r

-- tryWriteF -------------------------------------------------------------------

-- | tryWriteF for things susceptible to DeepSeq
_tryWrite :: IO a -> WriterT [SomeException] IO (Maybe a)
_tryWrite io = do
  io' <- liftIO (try io >>= evaluate)
  case io' of
    Left e  -> tell [e] >> liftIO (return Nothing)
    Right r -> (liftIO . return . Just) r

-- tryWriteF -------------------------------------------------------------------

-- | tryWriteF for things susceptible to DeepSeq
_tryWrite io = do
  io' <- liftIO (try io >>= evaluate)
  case io' of
    Left e  -> tell [e] >> liftIO (return Nothing)
    Right r -> (liftIO . return . Just) r

-- tryWriteF -------------------------------------------------------------------

-- | tryWriteF for things susceptible to DeepSeq