On 08/07/2012 06:25 PM, Martin Krejcirik wrote:
> Hi,
>
> using std.concurrency, is it possible to print an exception if a thread
> throws (and the main thread is still running) ? It just terminates and
> prints nothing. I tried to catch it and send as a message to the main
> thread, but haven't succeeded so far.

Here is an excerpt from a yet-unpublished change to my Concurrency chapter:

-----
The OwnerTerminated and LinkTerminated exceptions can be received as messages as well. The following code demonstrates this for the OwnerTerminated exception:



    bool isDone = false;

    while (!isDone) {
        receive(
            (int message)
            {
                writeln("Message: ", message);
            }
            ,

            (OwnerTerminated exc)
            {
                writeln("The owner has terminated; exiting.");
                isDone = true;
            }
        );
    }
-----

In order to receive LinkTerminated as a message, start the worker with spawnLinked() instead of spawn().

Ali

--
D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html

Reply via email to