我被要求使用boost :: exception创建“可定制的异常框架”。到目前为止,我只使用由我定义的简单例外。所以std :: exception,boost :: exception对我来说是新的。代码如下。向我介绍boost :: exception
#include <iterator>
#include<string>
#include <algorithm>
#include<errno.h>
struct My_exception:public virtual boost::exception
{
};
int main()
{
std::string fileName="tmp.txt";
std::string mode="r";
try
{
if(fopen(fileName.c_str(),mode.c_str()))
std::cout << " file opened " << std::endl ;
else
{
My_exception e;
e << boost::errinfo_api_function("fopen") << boost::errinfo_file_name(fileName)
<< boost::errinfo_file_open_mode(mode) << boost::errinfo_errno(errno);
throw e;
}
}
catch(My_exception e)
{
// extract the details here //
}
return 1;
}
现在,我想知道如何从捕获到的异常中提取数据。任何人都可以指导我在boost ::例外
@Nawaz,我无法理解它。你可以用代码 – prabhakaran 2011-02-05 06:21:19