C++ Exception没有被捕获

Geo*_*rge 1 c++ exception

我试图在我的链表空为止时抛出一个EmptyListException,但是如果我取消注释throw EmptyListException(),程序将继续终止.这是我的EmptyListException标头

#ifndef EMPTYLISTEXCEPTION_H
#define EMPTYLISTEXCEPTION_H

#include <stdexcept>
using std::out_of_range;
class EmptyListException : public out_of_range
{
    public:
        EmptyListException(): out_of_range("Empty List!\n") {}

};

#endif // EMPTYLISTEXCEPTION_H
Run Code Online (Sandbox Code Playgroud)

- 在Clist.h中抛出命令

template <typename E>
E Clist<E>::Remove() throw()
{
    if(isEmpty())
    {
        cout << "Empty List, no removal";
        //throw EmptyListException();
        return '.';
    }
        ... code
}
Run Code Online (Sandbox Code Playgroud)

- 赶上主要

try{
    cout << list->Remove() << endl;
} catch(EmptyListException &emptyList)
{
    cout << "Caught :";
    cout << emptyList.what() << endl;
}
Run Code Online (Sandbox Code Playgroud)

错误'此应用程序已请求运行时以不寻常的方式终止它.有关更多信息,请联系应用程序的支持团队.

Die*_*ühl 5

好吧,你告诉编译器你不要抛出你的任何例外Remove()!当您违反此承诺时,它会终止该程序.摆脱功能throw()声明,再试一次.