GOTOphobia considered harmful in C
The C version:<p><pre><code>    int* foo(int bar) {
        int* return_value = NULL;

        if (!do_something(bar))
            goto error_1;
        if (!init_stuff(bar))
            goto error_2;
        if (!prepare_stuff(bar))
            goto error_3;
        return_value = do_the_thing(bar);

    error_3:       cleanup_3();
    error_2:       cleanup_2();
    error_1:       cleanup_1();

        return return_value;
    }
</code></pre>
The D version:<p><pre><code>    int* foo(int bar) {
        scope(exit) cleanup1();
        if (!do_something(bar))
            return null;

        scope(exit) cleanup2();
        if (!init_stuff(bar))
            return null;

        scope(exit) cleanup3();
        return do_the_thing(bar);
    }
</code></pre>
<a href="https:&#x2F;&#x2F;dlang.org&#x2F;articles&#x2F;exception-safe.html" rel="nofollow">https:&#x2F;&#x2F;dlang.org&#x2F;articles&#x2F;exception-safe.html</a>