1

エラーキャッチをテストするために無効なインデックスの要素を調べようとしていますが、デバッグしようとすると 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

以前にこのエラーを経験したことがなく、修正方法がわからない場合は、どんな助けでも大歓迎です! :)

4

1 に答える 1

1

No Source Available は、デバッガー/IDE が、例外がキャッチされた場所 (またはあなたの場合はそうでない場所) に、現在の実行行がどこにあるかを示すために表示するソース コードがないことを通知するだけです。

あなたの例では、それをキャッチしていないので、自動生成されたコード (main() を呼び出す) の奥深くにあります。

At(5) 呼び出しの周りに try/catch を配置すると、そこで取得されます (そこにブレーク ポイントを配置すると仮定します)。

于 2012-11-14T03:26:53.277 に答える