How to kill whole application if child thread raises an exception?
dm via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 27 23:54:54 PDT 2016
On Thursday, 27 October 2016 at 13:37:29 UTC, Steven
Schveighoffer wrote:
>
> Hm... what about:
>
> import std.traits: Parameters;
>
> auto mySpawn(F)(F func, Parameters!F params)
> {
> static auto callIt(F func, Parameters!F params)
> {
> try
> {
> return func(params);
> }
> catch(Throwable t)
> {
> // print the exception/error, e.g.:
> import std.writeln;
> writeln(e.toString());
> // terminate program
> import core.stdc.stdlib : exit;
> exit(1);
> }
> }
>
> return spawn(&callIt, func, params);
> }
>
> void main()
> {
> auto tID = mySpawn(&func);
> ...
> }
>
> -Steve
I found the solution which works with dmd and ldc2:
...
import core.stdc.stdlib: _Exit;
_Exit(exitcode);
...
More information about the Digitalmars-d-learn
mailing list