Catch block not hit in unittest
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 24 06:47:32 PST 2016
On Thursday, November 24, 2016 13:42:25 Kagamin via Digitalmars-d-learn
wrote:
> Linux? Probably another bug.
> Try this:
> unittest
> {
> import core.exception : UnicodeException;
> void f()
> {
> string ret;
> int i = -1;
> ret ~= i;
> }
>
> try
> {
> f();
> }
> catch(UnicodeException e)
> {
> assert(e.msg == "Invalid UTF-8 sequence");
> }
> }
If you're doing that, you might as well use std.exception.assertThrown or
collectException. e.g.
assertThrown!UnicodeException(f());
or
assert(collectException!UnicodeException(f()).msg ==
"Invalid UTF-8 sequence.");
You could also do the same with a lambda to avoid the explicit function.
Regardless, I don't know why the OP is hitting this problem, and
unfortunately, I can't test it on my local machine at the moment to try and
see what's going on.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list