How to kill whole application if child thread raises an exception?

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 26 03:09:05 PDT 2016


On 26/10/2016 11:03 PM, dm wrote:
> On Wednesday, 26 October 2016 at 09:43:10 UTC, rikki cattermole wrote:
>> ```D
>> void entryPoint(alias func)() {
>>     try {
>>         func();
>>     } catch (Exception e) {
>>         import std.stdio;
>>         writeln(e.toString());
>>     }
>> }
>>
>> void main() {
>>     auto tid = spawn(&entryPoint!someFunc);
>>     // ...
>>
>> }
>> ```
>
> Well... This code shows me:
> object.Exception at thread.d(6): I'm an exception
> ----------------
>
> But my main thread still working :(
> Why so strange default behavior do not kill other threads in case some
> of threads raise exception?
> But thanks anyway.

If you throw an error it should crash the entire application.
But really you need to set up sync points within your application to 
allow it to die gracefully.


More information about the Digitalmars-d-learn mailing list