boost :: exception을 사용하여 "customizable exception framework"을 생성하라는 메시지가 나타납니다. 날까지 나는 나에 의해 정의 된 단순한 예외만을 사용했다. 그래서 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;
}
이제는 캐치 예외에서 데이터를 추출하는 방법을 알고 싶습니다. 사람이 부스트 :: 예외 모든
@Nawaz, 나는 그것을 이해할 수 없다. 당신은 코드 – prabhakaran
에서 이것을 보여줄 수 있습니까? @prabhakaran : 잠깐. 나는 샘플 코드를 작성하고있다. – Nawaz
@Nawaz 다음 오류가 발생합니다 – prabhakaran