Bug 14709 – dmd/samples/listener.d socket.accept exception handling is incorrect
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2015-06-17T18:57:00Z
Last change time
2015-08-31T12:03:44Z
Keywords
pull
Assigned to
nobody
Creator
kelethunter
Comments
Comment #0 by kelethunter — 2015-06-17T18:57:14Z
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();
Comment #1 by dlang-bugzilla — 2015-08-31T10:07:29Z