エラーキャッチをテストするために無効なインデックスの要素を調べようとしていますが、デバッグしようとすると 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
以前にこのエラーを経験したことがなく、修正方法がわからない場合は、どんな助けでも大歓迎です! :)