Source File: ex52.cpp
#include <fmt/core.h>
#include <chrono>
#include <thread>
#include <string>
void thrower() {
throw std::runtime_error("Kaboom!");
}
void weird_catcher() try {
auto res = std::string("abc").substr(10);
} catch(const std::exception& e) {
fmt::println("weird error: {}", e.what());
}
struct Bomber {
std::string subst;
Bomber(const std::string& test) try : subst(test.substr(10)) {
fmt::println("It worked!");
} catch(const std::exception& e) {
fmt::println("Bomber failed {}", e.what());
}
};
void cant_throw() noexcept {
thrower();
}
int main(int argc, char* argv[]) {
weird_catcher();
try {
thrower();
} catch(const std::exception& e) {
fmt::println("error! {}", e.what());
}
Bomber test{"thishasenoughchars"};
try {
Bomber kaboom{"not"};
} catch(...) {
fmt::println("Bomber go boom!");
}
fmt::println("Calling cant_throw()");
cant_throw();
}