// BoostEx.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <boost/exception/all.hpp> #include <boost/exception/get_error_info.hpp> #include <boost/current_function.hpp> #include <string> #include <iostream> using namespace std; using namespace boost; struct my_execption : virtual std::exception, virtual boost::exception { }; typedef boost::error_info<struct tag_err_no, int> err_no; typedef boost::error_info<struct tag_err_str, wstring> err_str; #define MY_THROW(exepction_str) throw my_execption()<<err_str(exepction_str)\ <<errinfo_api_function(__FILE__)\ <<errinfo_errno(__LINE__); int _tmain(int argc, _TCHAR* argv[]) { wcout.imbue(locale("chs")); //cout<<BOOST_CURRENT_FUNCTION<<endl; try { MY_THROW(_T("异常!")) } catch(boost::exception& e) { wcout<<_T("异常:")<<*get_error_info<err_str>(e)<<endl; cout<<"文件:"<<*get_error_info<errinfo_api_function>(e)<<endl; cout<<"行号:"<<*get_error_info<errinfo_errno>(e)<<endl; } return 0; }