Any way to peek at the exception currently being thrown?

Sebastiaan Koppe mail at skoppe.eu
Thu Jun 17 20:54:19 UTC 2021


On Thursday, 17 June 2021 at 20:35:42 UTC, Steven Schveighoffer 
wrote:
> Does someone know how to do this with current code? 
> Essentially, I want a reentrant transaction that either does 
> commit or rollback whenever the reentrance count goes to 0 and 
> either an exception is being thrown (rollback) or not (commit).
>
> -Steve

I typically add a transaction method to the connection that takes 
a delegate and executes the delegate in a try catch.

```dlang
auto transaction(Conn conn, void delegate(Conn) dg) {
   conn.begin();
   try {
     dg(conn);
     conn.commit();
   } catch (Exception e) {
     conn.rollback();
     throw e;
   }
}
```



More information about the Digitalmars-d mailing list