1
hermetic_cc_toolchain/test/boost_exception.cpp
2021-04-09 15:05:01 -07:00

21 lines
779 B
C++

#include <iostream>
#include <boost/lexical_cast.hpp>
int main() {
std::cout << "about to cast \"1\" to double!" << std::endl;
std::cout << boost::lexical_cast<double>("1") << std::endl;
std::cout << "about to cast \"z\" to double, but expecting to catch bad_lexical_cast" << std::endl;
try {
std::cout << boost::lexical_cast<double>("z");
std::cout << "uh-oh, should have thrown an exception before here." << std::endl;
} catch (const boost::bad_lexical_cast &e) {
std::cout << "caught bad_lexical_cast" << std::endl;
}
std::cout << "about to cast \"z\" to double, should see an uncaught exception." << std::endl;
std::cout << boost::lexical_cast<double>("z");
std::cout << "uh-oh, should have thrown an exception before here." << std::endl;
}