How to check for zero and negative values? What to do with "std::domain_error"?

Test 5


FAILED: REQUIRE_THROWS_AS( collatz_conjecture::steps(0), std::domain_error ) at /tmp/collatz-conjecture/collatz_conjecture_test.cpp:30

1 Like

Hi @ArtyomCoder, welcome to the Exercism Forum and thank you for posting! My name is Jonathan and Iā€™m the Community Manager - great to have you here.

If you could help us out by fleshing out the issue you are having with more detail that would be great. For example, is there a screenshot of your code? What was the issue specifically? What were you trying to do etc?

Currently it is a little tricky to understand what you need help with :slight_smile:


Look at the last two tests:

    REQUIRE_THROWS_AS(collatz_conjecture::steps(0), std::domain_error);

    REQUIRE_THROWS_AS(collatz_conjecture::steps(-15), std::domain_error);

They expect the function to throw an exception (specifically std::domain_error) if the parameter is non-positive.
For more about exceptions you might want to read Chapter 20: Exceptions at

1 Like

@ArtyomCoder Were you able to solve your problem? Let us know if you need help. Cheers!

1 Like