I have a Unit of Work implementation in .NET 4.7 that is checking to see if an exception has happened during the dispose. If there has, it calls rollback on a transaction. It is not catching the exception, or trying to handle it, it's simply trying to make sure the rollback happens if an exception occurs.
It's using;
Marshal.GetExceptionPointers() != IntPtr.Zero && Marshal.GetExceptionCode() != 0
I need to port this code to .NET Core 2.1. But GetExceptionPointers()
no longer exists, and GetExceptionCode
is marked as Obsolete, with no indication as to what replaces it. I'm not quite sure how to term what I'm looking for, but I need the equivalent behavior, so I can port over this code. Any thoughts?
To expand on this. This is a Unit Of Work implementation around an EF DbContext. It is currently working well, and if exceptions happen does successfully rollback any changes to the database. It can't have a try/catch inside of it, because this is used as such;
using(var uow = ctx.Begin())
{
.. code
}
I am not trying to handle exceptions inside this, I am trying to rollback the transaction while the exception is happening. This does appear to be a poor practice, I'm interested in learning an alternative, but I have to have the same behavior.