checking exceptions (first time user)

32 views
Skip to first unread message

John Długosz

unread,
May 7, 2018, 7:30:05 PM5/7/18
to CATCH
This is my first time using Catch2.  I started using it on a sample test project and ran into a question.


TEST_CASE ("parsing errors") {
    EqEv_t calc;
    CHECK_THROWS_AS ( calc.eval (" lady_bug = 17") , EqEv_t::parse_error );

    try {
        calc.eval (" lady_bug = 17");
    }
    catch (const EqEv_t::parse_error& err) {
        cout << "Exception details: " << err.what() << ", position= " << err.cursor << ", code= " << err.errcode << '\n';
    }
}

I can easily check that the expression throws the right kind of exception.

I’d like a succinct / good way to verify that the values carried by the exception are what I expected.  This is not formatted into the `what` string, but are data members.

What’s the right way to do that in Catch2?

Reply all
Reply to author
Forward
0 new messages