| 530 | |
| 531 | template <typename T> |
| 532 | void throw_or_mimic(const std::string& text) |
| 533 | { |
| 534 | static_assert(std::is_base_of<std::exception, T>::value, |
| 535 | "throw_or_mimic only works on std::exception and " |
| 536 | "deriving classes"); |
| 537 | |
| 538 | #ifndef CXXOPTS_NO_EXCEPTIONS |
| 539 | // If CXXOPTS_NO_EXCEPTIONS is not defined, just throw |
| 540 | throw T{text}; |
| 541 | #else |
| 542 | // Otherwise manually instantiate the exception, print what() to stderr, |
| 543 | // and exit |
| 544 | T exception{text}; |
| 545 | std::cerr << exception.what() << std::endl; |
| 546 | std::exit(EXIT_FAILURE); |
| 547 | #endif |
| 548 | } |
| 549 | |
| 550 | namespace values |
| 551 | { |