I need to find a way to test my exception handling in a function I wrote called hpx::parallel::copy. Other functions in the library such as hpx::parallel::transform are easy to test as a predicate can be passed in which throws an exception, but copy takes no predicate.
I think my best solution would be to use an iterator that throws on dereference somehow, though I'm not quite sure how to go about doing this......any other suggestions to solving this problem are welcome as well. Here is a code example of my problem
//transform.cpp , testing exceptions
bool caught_exception = false;
try {
base_iterator outiter = hpx::parallel::transform(policy,
iterator(boost::begin(c)), iterator(boost::end(c)), boost::begin(d),
[](std::size_t v) { //easy, predicate can be passed
throw std::runtime_error("test");
return v;
});
HPX_TEST(false);
}
//catching exceptions etc...
//copy.cpp, testing exceptions
bool caught_exception = false;
try {
base_iterator outiter = hpx::parallel::copy(policy,
iterator(boost::begin(c)), iterator(boost::end(c)), boost::begin(d)); //no predicate... how can I throw?
HPX_TEST(false);
}
//catching exceptions etc..
to be more specific, I want to be able to modify what exactly I want to throw in order to test multiple scenarios, this just means I can't use an implementation that throws out of range or other exceptions I can't control, I need to throw specific exceptions.