我在我的模板类Vector中创建了一个异常类来处理所有成员函数中的超出范围的错误,这些成员函数以索引为参数。我想知道如果索引超出范围,我如何抛出这种类型的异常?任何帮助都将不胜感激。
下面是exception类:
class IndexOutOfRangeException
{
public:
IndexOutOfRangeException(char* str, int i, int max, int min = 0)
:message(str),idx(i), last(max), first(min){};
friend ostream& operator<<(ostream&, const IndexOutOfRangeException&);
private:
char* message;
int idx;
int last;
int first;
};发布于 2015-04-30 13:50:34
First
为什么不直接使用std::out_of_range
throw std::out_of_range("Tried to access index 88 of the range [0, 10]");我想知道如果索引超出范围,我如何抛出这种类型的异常?
throw IndexOutOfRangeException("info", 88, 10, 0);https://stackoverflow.com/questions/29959897
复制相似问题