Specification of executing order of multiple scope(s)
bauss
jacobbauss at gmail.com
Fri Jun 2 19:15:19 UTC 2023
On Wednesday, 31 May 2023 at 15:52:08 UTC, An Pham wrote:
> Should the scope failure to be executed before exit regardless
> of the code order?
>
> import std.exception, std.stdio;
>
> void test()
> {
> writeln("test");
>
> scope (failure)
> {
> writeln("failure");
> }
>
> scope (exit)
> {
> writeln("exit");
> }
>
> throw new Exception("exception");
> }
>
> void main()
> {
> try
> {
> test();
> }
> catch (Exception e) writeln(e.msg);
> }
>
> Output
> test
> exit
> failure
> exception
Just move the exit scope guard before failure and it will do what
you want.
More information about the Digitalmars-d
mailing list