#include <iostream>
#include <stdexcept>
#include "HCheckConfig.h"
#include "catch.hpp"
const bool dev_run = false;
void invalidArgument() {
throw std::invalid_argument("Exception: invalid_argument");
}
void logicError() {
throw std::logic_error("Exception: logic_error");
}
void badAlloc() {
throw std::bad_alloc();
}
TEST_CASE("ThrowCatch", "[highs_test_throw]") {
bool ok;
ok = false;
try {
invalidArgument();
} catch (const std::invalid_argument& exception) {
if (dev_run) std::cout << exception.what() << std::endl;
ok = true;
}
REQUIRE(ok);
ok = false;
try {
logicError();
} catch (const std::logic_error& exception) {
if (dev_run) std::cout << exception.what() << std::endl;
ok = true;
}
REQUIRE(ok);
ok = false;
try {
badAlloc();
} catch (const std::bad_alloc& exception) {
if (dev_run) std::cout << exception.what() << std::endl;
ok = true;
}
REQUIRE(ok);
ok = false;
try {
invalidArgument();
} catch (const std::exception& exception) {
if (dev_run) std::cout << exception.what() << std::endl;
ok = true;
}
REQUIRE(ok);
ok = false;
try {
logicError();
} catch (const std::exception& exception) {
if (dev_run) std::cout << exception.what() << std::endl;
ok = true;
}
REQUIRE(ok);
ok = false;
try {
badAlloc();
} catch (const std::exception& exception) {
if (dev_run) std::cout << exception.what() << std::endl;
ok = true;
}
REQUIRE(ok);
}