www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - sending an Exception and print it

reply "Dan Killebrew" <nospam gmail.com> writes:
I'm sending an exception from a worker thread to the owner thread
to be logged/printed. Using DMD64 D Compiler v2.064


Using std.concurrency prevents me from passing a naked Exception.
So the owner receives either a shared or immutable Exception.
I can't format a shared Exception:
/usr/include/dmd/phobos/std/format.d(2602): Error: static assert
"unable to format shared objects"
I can't format an immutable Exception:
/usr/include/dmd/phobos/std/format.d(2610): Error: template
instance formatObject!(Appender!string, immutable(Exception),
char) does not match template declaration formatObject(Writer, T,
Char)(ref Writer w, ref T val, ref FormatSpec!Char f) if
(hasToString!(T, Char))

What gives? I expected the immutable Exception to be formattable.

My current workaround is to cast to const Exception. Is there
something else I should be doing here?
Dec 21 2013
parent "Dan Killebrew" <nospam gmail.com> writes:
I just wanted to add that the "can't format immutable Exception" 
also prevents me from doing this:
   auto exception = receiveOnly!(immutable Exception)();
because receiveOnly creates a tuple which implements a toString 
that uses indirectly uses formatObject. So I'm forced to use the 
slightly more clunky recieve() as seen on DPaste.
Dec 21 2013