Truly @nogc Exceptions?

Adam D. Ruppe destructionator at gmail.com
Thu Sep 20 15:33:40 UTC 2018


On Wednesday, 19 September 2018 at 21:16:00 UTC, Steven 
Schveighoffer wrote:
> As Andrei says -- Destroy!

Nah, I agree. Actually, I'm of the opinion that string error 
messages in exceptions ought to be considered harmful: you 
shouldn't be doing strings at all. All the useful information 
should be in the type - the class name and the members with 
details.

Well, defining a new class can sometimes be a mild hassle... but 
for really common ones, we really should just do it, and other 
ones can be done as templated classes or templated factory 
functions that define a new class right there and then.

http://arsdnet.net/dcode/exception.d

That's the proof-of-concept I wrote for this years ago, go to the 
bottom of the file for the usage example. It uses a reflection 
mixin to make writing the new classes easy, and I even wrote an 
enforce thing that can add more info by creating a subclass that 
stores arguments to functions so it can print it all (assuming 
they are sane to copy like strings or value things lol)

	enforce!fopen("nofile.txt".ptr, "rb".ptr);

MyExceptionBase at exception.d(38): fopen call failed
         filename = nofile.txt
         mode = rb
----------------


More information about the Digitalmars-d mailing list