www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to catch RangeError in unittest?

reply wjoe <invalid example.com> writes:
I have a function add(index, data) which throws RangeError if the 
index is invalid.

unittest { // is supposed to test that RangeError is thrown on a 
range violation
    assertThrown!RangeError(add(size_t.max, something)); //which 
doesn't work, the test is killed with core.exception.RangeError: 
Range violation

    // this kills the test, too: core.exception.RangeError: Range 
violation
    try {
      add(size_t.max, something);
      assert(false, "Expecting RangeError");
    } catch (RangeError) {}
}

Just for clarification, I do _not_ intend to catch RangeError 
outside of a unittest. What I want is that the test acknowledges 
the correctly thrown RangeError and gracefully reports success.


What are my options?
Feb 18 2020
parent wjoe <invalid example.com> writes:
On Tuesday, 18 February 2020 at 13:07:35 UTC, wjoe wrote:
 I have a function add(index, data) which throws RangeError if 
 the index is invalid.
Never mind. For whatever reason RangeError is now caught. Sorry for the noise.
Feb 18 2020