DMD 0.160 release

Sean Kelly sean at f4.ca
Fri Jun 9 09:18:15 PDT 2006


Brad Roberts wrote:
> On Fri, 9 Jun 2006, Walter Bright wrote:
> 
>> I'll take the private off, but a msg field would be redundant with the one in
>> the base class.
> 
> Ok.. good point.  One interesting difference, though.  The base class' msg 
> field will end up holding the entire message.  ie:
> 
> assert(false, "hi") -->
>    AssertError Failure assert-test.d(40) hi
> 
> My intent was to capture just the "hi" part.  My choice of 'msg' in the 
> diff I pasted was unfortunate.  I'd originally called it 'message'.

For what it's worth, I typically assign the msg field to the string 
passed on object construction, and if a more expressive message is 
required I'll override toString in the derived exception object.  This 
avoid the need for any allocations at the throw point (beyond the object 
itself, potentially), but still provides a means for more structured 
error messages to be displayed.  The actual error reporting structure I 
use in dmain2 is this:

   catch (Exception e)
   {
     while (e)
     {
       if (e.file)
         fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg);
       else
         fprintf(stderr, "%.*s\n", e.toString());
       e = e.next;
     }
     exit(EXIT_FAILURE);
   }

Typically, I think the full message is useful only if context 
information is not provided explicitly in the file and line members.


Sean



More information about the Digitalmars-d-announce mailing list