Throwable class design

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 31 17:05:36 PST 2013


On Fri, Feb 01, 2013 at 01:47:35AM +0100, Andrej Mitrovic wrote:
> 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.

+1. Like this idea, I'll have to start using it to avoid the headache of
trying to figure out where something blew up when the stacktrace points
to some deep obscure code inside Phobos.


T

-- 
People tell me that I'm skeptical, but I don't believe it.


More information about the Digitalmars-d mailing list