Я пытаюсь использовать следующий код для проверки "set_unexpected ()".Я ожидаю, что код сгенерирует вывод наподобие:
In function f(), throw const char* object
Call to my_unexpected
Exception in main(): Exception thrown from my_unexpected
Но я получил ошибку времени выполнения: «Это приложение запросило среду выполнения, чтобы завершить его необычным способом»Итак, в чем будет проблема?Спасибо
struct E {
const char* message;
E(const char* arg) : message(arg) { }
};
void my_unexpected() {
cout << "Call to my_unexpected" << endl;
throw E("Exception thrown from my_unexpected");
}
void f() throw(E) {
cout << "In function f(), throw const char* object" << endl;
throw("Exception, type const char*, thrown from f()");
}
int _tmain(int argc, _TCHAR* argv[])
{
set_unexpected(my_unexpected);
try {
f();
}
catch (E& e) {
cout << "Exception in main(): " << e.message << endl;
}
return 0;
}