// 捕获、处理异常的代码片段,高手勿笑~
// 代码片段 // test.cpp // 编译方法: g++ -o test test.cpp
#include<iostream>
#include<boost/lexical_cast.hpp>
int main() {
try {
int a = boost::lexical_cast<int>("123.456");
std::cout << a <<std::endl;
return 0;
}
catch(boost::bad_lexical_cast& e) {
std::cout<< "Exception catched." << std::endl;
}
}