Comparing Exceptions and Errors
Steven Schveighoffer
schveiguy at gmail.com
Wed Jun 15 20:46:56 UTC 2022
On 6/15/22 3:51 PM, kdevel wrote:
> On Wednesday, 15 June 2022 at 03:09:56 UTC, Steven Schveighoffer wrote:
>> I don't see what you see wrong with the code I wrote. It's
>> straightforward, obvious, and does the job I need it to do, in a way
>> that's not prone to future mistakes.
>
> Sometimes it is not easy to explain why code "feels" wrong and in the
> case of
>
> ```
> scope(success) conn.exec("COMMIT");
> ```
>
> it was not that clear to me some days ago. The reason why I would not write
> it is: `conn.exec("COMMIT")` may throw! Think of deferred constraints
> which are checked not before the commit. But "[a] [...] scope(success)
> statement may not exit with a throw [...]" [1]
>
> [1] https://dlang.org/spec/statement.html#ScopeGuardStatement
I do depend on the commit (and the rollback) not throwing. I probably
should swallow any exceptions at that point, and close the connection.
It has not harmed my code though. I tried throwing inside a scope guard,
and it.... just works, I'm not sure why you can't throw in those?
I've been meaning to add a reentrant transaction system to mysql-native,
because I hate that I can't do nested transactions. That would solve
that problem and this problem, by giving me a nothrow function to call
in the scope guard.
-Steve
More information about the Digitalmars-d-learn
mailing list