function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anna425912anna425912 

In a try/catch/finally statement, if the try portion succeeds but finally portion fails, is the try portion rolled back?

I have a class that has a future call that first has a try which has a callout in it, a catch that sends an email notification, and a finally which updates a custom setting.  However, I am getting cases where the try seems like it should have worked because I'm not getting an email notification from the catch statement, but the finally portion fails to update the custom setting. Then when I go to check if the try portion succeeded, the records haven't been updated.  
Ravikant kediaRavikant kedia
I search about it and find that if the try portion succeeds but finally portion fails then try portion not rolled back.
anna425912anna425912
It also seems like, if I'm understanding correctly, if an exception is thrown in the try statement and in the finally statement it is the only exception shown.  So my guess is that the try is actually failing but the exception is not being shown for that because it's being swallowed by the finally exception.
Ravikant Saini 1Ravikant Saini 1
I think it is exception in finally block before update custom setting or at the time of update custom setting. You can also use try catch in finally block If you perform such operation which can throw an exception.