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

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 26 02:56:33 PDT 2016


On Wednesday, 26 October 2016 at 09:43:10 UTC, rikki cattermole 
wrote:
> Basically when you spawn a thread giving the function, you pass 
> it through another function which will catch any exceptions not 
> normally caught.
>
> Of course this really should be the default behavior but 
> somebody else may be more of a help here.
>
> And it is pseudo code, so please don't expect it to 100% work 
> as I have written it.
>
> ```D
> void entryPoint(alias func)() {
> 	try {
> 		func();
> 	} catch (Exception e) {
> 		import std.stdio;
> 		writeln(e.toString());
> 	}
> }
>
> void main() {
> 	auto tid = spawn(&entryPoint!someFunc);
> 	// ...
> 	
> }
> ```

It doesn't return. It still have to be killed by hand. (at least 
on Linux)


More information about the Digitalmars-d-learn mailing list