On Saturday 06 November 2010 18:35:29 Nick Sabalausky wrote:
> "Jonathan M Davis" <jmdavisp...@gmx.com> wrote in message
> news:mailman.138.1289084125.21107.digitalmar...@puremagic.com...
> 
> > On Saturday 06 November 2010 12:28:02 Masahiro Nakagawa wrote:
> >> I don't know this module's usability, but is getExcMsg useful?
> >> I can't imagine useful situation.
> >> In addition, I grepped your datetime.d and getExcMsg not found :(
> >> 
> >> If possible, I want the mock, stub and related features.
> > 
> > It's used to test unittests.d itself, but I don't think that I'm using it
> > in
> > datetime.d at the moment. The idea is to use it if you want to verify
> > that an
> > exception says exactly what you want it to say (especially if you could
> > get
> > multiple exceptions of the same type but with different messages from a
> > function). I will grant you, however, that it's one of the less useful
> > functions.
> 
> I'm not suggesting getExcMsg be removed, but if you ever need to verify an
> exception's message is exactly matches a specific string, then you're
> almost certainly using exceptions the wrong way to begin with.

The reason I created it originally IIRC was to verify stuff like the fact that 
passing an invalid hour to TimeOfDay complained about the hour being incorrect 
rather than the minute or the second. It _is_ arguably error-prone, because 
it's 
testing the _exact_ error message, but if you're trying to verify that the 
correct exception was thrown and multiple exceptions of the same type can be 
thrown from a function, I don't really see any other way to do it. I ended up 
not using it in std.datetime (probably because I consolidated most of the code 
which threw DateTimeExceptions, so there was less need for it), but I do think 
that it's at least potentially useful if you want to verify that your 
exceptions 
have the correct error messages.

- Jonathan M Davis

Reply via email to