我正在尝试查看无效索引处的元素以测试我的错误捕获,但是当我尝试调试它时,我不断收到 No Source Available 或当我尝试正常运行它时收到 Unhanded Exception Error:
#include <iostream>
#include "MyArray.h"
using namespace std;
int main()
{
MyArray<int> arr1;
MyArray<int> arr2(2);
arr2.Add(11);
arr2.Add(22);
arr2.Add(33);
arr2.At(5); // Test to check error
system("pause");
return 0;
}
arr2.At(5);
在我的 MyArray.h 文件中调用这个函数,我得到了我的错误:
// MyArray.h
template <class elemType>
elemType & MyArray<elemType>::At(int index)
{
if (index < 0 || index >= _size)
throw "elemType & MyArray<elemType>::At(int index) Index out of range!"; // Where the problem is
return list[index];
}
正常运行时出现的错误:
Unhandled exception at 0x763ec41f in MyArrayProject.exe: Microsoft C++ exception: char at memory location 0x0032fa60..
当我尝试调试它arr2.At(5);
并命中时出现错误throw "elemType & MyArray<elemType>::At(int index) Index out of range!";
:
No Source Available
There is no source code available for the current location.
Call stack location:
msvrc100d.dll!_CxxThrowException(void * pExceptionObject, const_s__ThrowInfo) Line 91
以前没有遇到过这个错误并且不确定如何修复它,任何帮助将不胜感激!:)