On Friday, 11 July 2014 at 07:45:24 UTC, bearophile wrote:
Joseph Rushton Wakeling:
I've habitually used 'format' to prepare assert messages with
variable content, which has a similar problem -- IIRC it
conflicts with nothrow and I guess it too would conflict with
@nogc.
A solution is to add to Phobos a way to format to an output
range, where the range you use a stack-allocated array of chars
large enough to contain your formatted message. So on the whole
it can be @nogc.
Bye,
bearophile
Although I think that is certainly something that would be
helpful/necessary, it wouldn't solve the problem of printing out
assert messages/exception messages.
Basically, the only way I could think to do it is to make a
special `NoGCException` that has a `detailMsg` function (taking a
`sink`, of course) and your subclass of `NoGCException` would
store all the info necessary to print out the error at the catch
site and you'd just overload `detailMsg` to print it out properly.
https://gist.github.com/Zshazz/47ed52c3246e5348062a
That's an example. I store info at line 84 as a tuple in my
`SpecialNoGCException`, and set the storage when I'm about to
throw at line 202. My apologies for the poor code (I made that
stuff as an experiment). It works, but pre-allocating the initial
exception is still problematic, IMO. I'd really like a way of
specifying that an exception was malloc'd and it's the catcher's
job to free it. Obviously, I could "just do it" but it seems
pretty unsafe and error-prone. *shrug*