Howto catch SocketOSException?

bauss via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 26 11:50:13 PDT 2017


On Sunday, 26 March 2017 at 11:46:39 UTC, Jolly James wrote:
> On Sunday, 26 March 2017 at 11:35:00 UTC, Jolly James wrote:
>> [...]
>
> Found out something: You cannot catch any exception thrown in 
> the listen()-method in general.
>
>
> ■ Original code:
>>[...]
>
>
> ■ Modified one:
>>[...]
>
>
> ■ Not working try-catch:
>>[...]

Chances are it's invoked in another thread and thus you can't 
catch it like that.

To sum it up.

Ex.

void thisFunctionThrows() { ... }

void ableToCatch() {
     try {
         thisFunctionThrows();
     }
     catch (Exception e) {
         // We can catch the exception ...
     }
}

void notAbleToCatch() {
     try {
         spawn(&thisFunctionThrows);
     }
     catch (Exception e) {
         // We cannot catch the exception ...
     }
}

void ableToCatchToo() {
     spawn(&ableToCatch); // We're able to handle the exception, 
because the try/catch is handled in the thread that calls the 
function that throws.
}


More information about the Digitalmars-d-learn mailing list