std.locale
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Mar 2 11:14:32 PST 2009
Sergey Gromov wrote:
> Mon, 02 Mar 2009 07:02:10 -0800, Andrei Alexandrescu wrote:
>
>> Consider some code in phobos that must throw an exception:
>>
>> throw Exception("File `%s' not found, system error is %s.",
>> filename, errnomsg);
>>
>> The localized version will look like this:
>>
>> auto format = "File `%s' not found, system error is %s.";
>> auto localFormat = currentLocale ? currentLocale.peek(format) : null;
>> if (!localFormat) localFormat = format;
>> throw Exception(localFormat, filename, errnomsg);
>
> This example does not address the encoding problem. Currently, errnomsg
> is in Russian, UTF-8 encoded. So I get "system error is <garbage>" on
> the console. If you adopt locales I'll get garbage not only for the
> system error but for the rest of the exception message as well.
>
> To actually solve this problem the default exception handler must be
> fixed to convert any UTF-8 into the current OEM code page before
> printing. It would also help if default stdin and stdout performed such
> a conversion.
I see.
>> What happens is that the default format string _is_ the key for looking
>> up the localized strings.
>
> Nice. This means that error messages become a part of API and are
> subject to backward and forward compatibility issues. Isn't it too
> much?
I think it isn't too much, considering the sorry state of affairs of
today's exceptions. You can't even answer the question: "Given this
FileException object, what file name was concerned?" And each module
defines its own exception class that is equally useless. It's
ridiculous. 95% of them must be removed. And we must have systematic
formatting of all strings initiated by Phobos.
Andrei
More information about the Digitalmars-d
mailing list