thread exceptions
Martin Krejcirik
mk-junk at i-line.cz
Wed Aug 8 01:52:47 PDT 2012
Hi Ali,
On 8.8.2012 5:36, Ali Çehreli wrote:
> The OwnerTerminated and LinkTerminated exceptions can be received as
> messages as well. The following code demonstrates this for the
> OwnerTerminated exception:
I meant how can I print the actual exception from the thread, including
it's error message, stack trace etc. Consider code like this, it just
ends without any error message:
import std.concurrency, std.stdio;
void main()
{
writeln("main start");
spawn(&child);
for (int i=0; i<1_000_000_000; i++) {};
writeln("main end");
}
void child()
{
writeln("thread start");
for (int i=0; i<100_000; i++) {};
writeln("thread end");
throw new Exception("exception from thread");
}
If I use spawnLinked, I know the thread ended, but still no original
exception. If I change main() to terminate before child(), it actually
waits until the child finishes and prints the exception, so there has to
be a way.
--
mk
More information about the Digitalmars-d-learn
mailing list