thread exceptions
Sean Kelly
sean at invisibleduck.org
Wed Aug 8 08:32:17 PDT 2012
I'll have to think about it. The current approach in std.concurrency is intended to be forwards-compatible with interprocess messaging, and serializing/deserializing an arbitrary exception would be tricky. See the exception thrown by receiveOnly as an example of how I addressed the issue there.
On Aug 8, 2012, at 1:52 AM, Martin Krejcirik <mk-junk at i-line.cz> wrote:
> 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