...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <exception>
#include <string>
namespace my {
struct string : std::string {
explicit string(const char *msg,
const std::string::allocator_type &alloc = std::string::allocator_type{}) noexcept
try : std::string(msg, alloc) {} catch(...) {
extern void log_message(const char *) noexcept;
log_message("std::string constructor threw an exception");
std::terminate();
}
// ...
};
}
static const my::string global("...");
int main() {
// ...
} |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <exception>
int f_helper() noexcept {
try {
extern int f() noexcept(false);
return f();
} catch (...) {
extern void log_message(const char *) noexcept;
log_message("f() threw an exception");
std::terminate();
}
// Unreachable.
}
int i = f_helper();
int main() {
// ...
} |
...