1

I have two grain method marked as TransactionOption.CreateOrJoin, which is invoked by another grain method marked as TransactionOption.Create. I want to abort all process if any of two grain method marked as TransactionOption.CreateOrJoin failed. Should I throw an exception like this? Or is there any solution to abort all process?

await _balance.PerformUpdate(q =>{
   if (q.Amount + amount > _balanceLimit)
   {
     throw new ApplicationException("limit exceeded");
   }  
   
   q.Amount += amount;
});
  • 3
    Many people (including me) say, you should not use exceptions for flow control. You're checking for a common situation (> limit) and that's nothing unexpected. You could return a result that includes if operation succeeded instead. S.a. https://stackoverflow.com/questions/729379/why-not-use-exceptions-as-regular-flow-of-control#:~:text=Using%20exceptions%20for%20flow%20control,throw%20code%20be%20quite%20inefficient. – Christoph Lütjen Dec 23 '20 at 10:47

0 Answers0