[Issue 7675] std.format needs better exception messages

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 24 16:11:27 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=7675


Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-01-24 16:11:25 PST ---
The situation seems to be better now:

import std.string;
void main()
{
    string res = format("%s %s", 1);
}

> std.format.FormatException at D:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\format.d(431): Orphan format specifier: %%s %s

Slightly confusing message, as it thought it was going to print '%s' but it
prints the entire string.

And the other message:

import std.string;
void main()
{
    string res = format("%s %s", 1, 2, 3);
}

> std.format.FormatException at D:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\string.d(2536): Orphan format arguments: args[2..3]

I'm quite satisfied that this was implemented. Although the stack trace still
sucks as I've yet to get proper line numbers. 

But at least I don't have to count the specifiers in a wrapper function, I just
have to catch FormatExceptions:

string safeFmt(string file = __FILE__, size_t line = __LINE__, Args...)(string
fmt, Args args)
{
    try
    {
        return format(fmt, args);
    }
    catch (FormatException exc)
    {
        exc.file = file;
        exc.line = line;
        throw exc;
    }
}

void main()
{
    auto x = safeFmt("%s", 1, 2);
}

How great is that?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list