1
我試圖查看無效索引處的元素來測試我的錯誤捕獲,當我嘗試調試它時遇到無源代碼或嘗試運行時出現Unhanded Exception Error它通常爲:沒有來源可用throw throw
#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
以前沒有經歷過這種錯誤,不知道應該如何解決這個問題,任何幫助將不勝感激! :)
我忽略了!謝謝! –