Comparing Exceptions and Errors
bauss
jj_1337 at live.dk
Thu Jun 16 11:28:32 UTC 2022
On Thursday, 16 June 2022 at 10:07:23 UTC, kdevel wrote:
> On Wednesday, 15 June 2022 at 20:46:56 UTC, Steven
> Schveighoffer wrote:
>> [...]
>> 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?
>
> You can but that is not acceptable for the spec explicitly
> forbids that:
>
> https://dlang.org/spec/statement.html#scope-guard-statement
>
> Quote (again): "A [...] scope(success) statement may not exit
> with a throw [...]."
>
> Furthermore I always thought of scope guards as a means for
> cleanup. Cleanup implies in my eyes removing things which have
> been used in a previous task. This intended use is documented
> here:
>
> https://tour.dlang.org/tour/en/gems/scope-guards
>
> Using scope guards makes code much cleaner and allows
> resource allocation
> and clean up code to be placed next to each other. These
> little helpers also
> improve safety because they make sure certain cleanup code
> is always called
> independent of which paths are actually taken at runtime.
>
> Performing a COMMIT is rather the opposite of cleanup: It makes
> (writes) changes to the database persistent.
If the spec forbids it, but the compiler allows it, wouldn't it
then be a bug?
More information about the Digitalmars-d-learn
mailing list