collectExceptionMsg and emptyExceptionMsg

Jonathan M Davis jmdavisProg at gmx.com
Wed Apr 18 10:52:30 PDT 2012


On Wednesday, April 18, 2012 19:32:44 Andrej Mitrovic wrote:
> On 4/18/12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> > Probably to avoid any issues of null vs empty
> 
> But what I'm saying is an empty string isn't null.

True. But by avoiding the empty string, the entire issue of null == "" is 
avoided.

> > It also makes it very clear
> > that you got an empty exception message when printing the message, whereas
> > there won't be any difference between null and empty when you do something
> > like
> > 
> > writeln(collectExceptionMessage(foo()));
> 
> Well typically you would write the file and line number, or use
> specific formatting such as writefln('%s', str).

Which wouldn't help any in showing the difference between an empty message and 
there being no exception at all.

> It seems odd to return a sentry value
> instead of a simple empty literal "", no other phobos string function
> that I know of uses this technique.

They also almost never care about null vs empty.

Maybe it _would_ be better if it returned "" rather than emptyExceptionMsg, 
but it has to avoid returning null when there's actually an exception, and 
having emptyExceptionMsg both avoids any issues with null == "" and makes it 
much clearer when you print the string.

You can certainly create a pull request for it if you want. I don't know what 
the other Phobos devs would think about it. Personally, I'm always a bit leery 
of relying on the difference between empty and null given the ridiculousness 
that is null == "".

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list