[Issue 14709] New: dmd/samples/listener.d exception handling is poor

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 17 11:57:14 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14709

          Issue ID: 14709
           Summary: dmd/samples/listener.d exception handling is poor
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: kelethunter at gmail.com

In commit 1910c6dabd357c644c07bbb6143ffcef8d8dde6a the exception handling in
dmd/samples/listener.d was changed from the original try, catch to a
scope(failure). Which is fine; however, line 84 and beyond shows:

>Socket sn = listener.accept();
>scope (failure)
>{
>    writefln("Error accepting");
>
>    if (sn)
>        sn.close();
>}

If listener.accept() generates an exception, the example will die with that
exception, as the scope(failure) comes after the call. I think it should be
something like this:

>Socket sn = void;
>scope (failure)
>{
>    writefln("Error accepting");
>
>    if (sn)
>        sn.close()
>}
>Socket sn = listener.accept();

--


More information about the Digitalmars-d-bugs mailing list