Exception isn't thrown as expected

Ali Çehreli acehreli at yahoo.com
Mon Jun 3 09:14:58 PDT 2013


On 06/03/2013 12:30 AM, Alexandr Druzhinin wrote:

 > if child thread throws an exception,
 > should it print some diagnostic message to clear that it crashed or no?

No, the parent does not know about such a termination. These are the 
following options that I know of:

1) The exceptions can be caught by the child and sent to the owner 
explicitly as a special message that both understand.

Or the exception can directly be passed as a message:

2)
     try {
         // ...

     } catch (shared(Exception) exc) {
         owner.send(exc);
     },

The owner receives that message just like a message:

     receive(
         // ...

         (shared(Exception) exc) {
             throw exc;
         });

The code above re-throws the child's exception in the owner's context 
but it could do anything else as well.

There are also the following exceptions that are related to std.concurrency:

* MessageMismatch
* OwnerTerminated
* LinkTerminated
* MailboxFull
* PriorityMessageException

I have some examples here:

   http://ddili.org/ders/d.en/concurrency.html

Ali



More information about the Digitalmars-d-learn mailing list