Using Exceptions as a general error handling strategy within an acid-state update/query won't work, read the point about stateNestedError1 here.
Until now I have been using the following pattern for error handling:type MyUpdate st e a = StateT st (Either e) a runMyUpdate :: MyUpdate st e a -> Update st (Either e a) runMyUpdate act = do s <- get case runStateT act s of Left e -> return $ Left e Right (x,s') -> do put s' return $ Right x setVal' :: Int -> MyUpdate Int String () setVal' 5 = throwError "wrong number" setVal' x = put x setVal :: Int -> Update Int (Either String ()) setVal = runMyUpdate . setVal' makeAcidic ''Int ['setVal]
But I realize that this will still write the failing update to the event log, so you will have a lot of transactions in the log that don't modify the state. An alternative would be for runMyUpdate to throw an Exception instead (this will be ok since the exception is not nested).
What error handling strategies are other acid-state users using?submitted by ttfh
[link] [5 comments]