Howto catch SocketOSException?
Jolly James via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 26 04:46:39 PDT 2017
On Sunday, 26 March 2017 at 11:35:00 UTC, Jolly James wrote:
> On Sunday, 26 March 2017 at 02:41:46 UTC, Adam D. Ruppe wrote:
>> On Sunday, 26 March 2017 at 02:24:56 UTC, Jolly James wrote:
>>> You can ignore the loop()-method. It is not called as the
>>> application will never reach this statement, because it
>>> cannot, because it crashes already in the listen()-method in
>>> consequence of the exception that does not get caught by the
>>> try-catch block.
>>
>> Try putting it in the try anyway and see what happens.
>>
>> It is an async socket library, they can do weird things.\
>
> Unfortunately not working either. I should not forget to
> mention that the exception also raises when the code does not
> contain the loop()-call.
Found out something: You cannot catch any exception thrown in the
listen()-method in general.
■ Original code:
>auto addressInfos = getAddressInfo(addr, to!string(port),
>AddressInfoFlags.PASSIVE, SocketType.STREAM, ProtocolType.TCP);
■ Modified one:
>AddressInfo[] addressInfos;
>
>try
>{
> addressInfos = getAddressInfo(addr, to!string(port),
>AddressInfoFlags.PASSIVE, SocketType.STREAM, ProtocolType.TCP);
>}
>catch(SocketOSException e)
>{
> throw new Exception("Invalid address: " ~ addr, e);
>}
■ Not working try-catch:
> try
> {
> tcp.listen(2345, "127.0.0.1c");
> socketManager.loop();
> }
> catch (Exception e)
> {
> return;
> }
More information about the Digitalmars-d-learn
mailing list