我试图在我的链表空为止时抛出一个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)
错误'此应用程序已请求运行时以不寻常的方式终止它.有关更多信息,请联系应用程序的支持团队.