当我的链表是空的时,Im试图抛出一个EmptyListException,但是如果我取消注释throw EmptyListException(),程序会一直终止。 这是我EmptyListException头C++异常不被捕获
#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
- 在Clist.h扔命令
template <typename E>
E Clist<E>::Remove() throw()
{
if(isEmpty())
{
cout << "Empty List, no removal";
//throw EmptyListException();
return '.';
}
... code
}
- 抓主
try{
cout << list->Remove() << endl;
} catch(EmptyListException &emptyList)
{
cout << "Caught :";
cout << emptyList.what() << endl;
}
错误“此应用程序已请求运行时以不寻常的方式终止它。请联系应用程序支持团队以获取更多信息。
为什么'回报;' ''? E不一定是字符。 – LeeNeverGup
尝试从Remove()的定义中移除'throw()'。 – xaizek
return'。';我只想结束这个功能,我想发回一个空的数据类型。通常这个函数返回被删除的节点数据 – George