Search code examples
c++unhandled-exceptionthrow

No Source Available throw


I'm trying to look at an element at an invalid index to test my error catching, nut I keep getting a No Source Available when I try to debug it or a Unhanded Exception Error when I try to run it normally:

#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); calls this function in my MyArray.h file, where I'm getting my error:

// 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];
}

Error that I get when I run it normally:

Unhandled exception at 0x763ec41f in MyArrayProject.exe: Microsoft C++ exception: char at memory location 0x0032fa60..

Error that I get when I tried to debug it at arr2.At(5); and it hits 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

Haven't experienced this error before and unsure of how to fix it, any help would be much appreciated! :)


Solution

  • The No Source Available is just the debugger/IDE telling you that where the exception was caught (or not in your case), it doesn't have the source code to display to show you where its current line of execution is.

    In your example you aren't catching it so it'll be in the depths of the auto generated code (that calls main()).

    Put a try/catch around the At(5) call and it'll grab it there (assuming you put a break point there).