Throwable class design

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Jan 31 16:47:35 PST 2013


On 2/1/13, Sean Kelly <sean at invisibleduck.org> wrote:
> I think the reason is mostly historic--the original exception classes had
> public members.  There's no reason why they couldn't be hidden behind
> read-only properties though, other than the potential to break existing
> code.

I'd rather we not, it's useful being able to modify msg and line
sometimes, e.g.:
http://forum.dlang.org/thread/uudharkmihxjymsxcyxq@forum.dlang.org#post-mailman.855.1359491827.22503.digitalmars-d-learn:40puremagic.com

Another example, wrapping `format` to inject the local file and line:

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

Saves me from having to read a broken stack trace or file and line
within Phobos.


More information about the Digitalmars-d mailing list