Hey guys, I am trying to learn about exceptions and thought that I would include an exception handler in a homework assignment. Basically I have made a function range_checker which returns a bool value if the vector subscipt is within range or not.
I use the function to check for subscript range on int and string vectors. The functions works perfectly when the int vector subscipt is in and out of range and also when the string subscript is within range.
When i use the range_check function for bounds checking on a subscipt that is out of range, the program goes nuts and loads of text appears in the program window. The alarm bell (beep) also sounds continuously.
I have included just the function for simplicity but if anything else is required just shout.
The error given by the compiler is:
I use the function to check for subscript range on int and string vectors. The functions works perfectly when the int vector subscipt is in and out of range and also when the string subscript is within range.
When i use the range_check function for bounds checking on a subscipt that is out of range, the program goes nuts and loads of text appears in the program window. The alarm bell (beep) also sounds continuously.
I have included just the function for simplicity but if anything else is required just shout.
Rich (BB code):
template<typename T>
bool attendance::range_check(const vector<T>&V, int location) const
{
try
{
if (V.size() < static_cast<unsigned int>(location) +1)
throw exception("Out of range");
else return true;
}
catch (exception &error)
{
cerr << "Error occurred: " << error.what() << endl << "location was: " << location << endl;
return false;
}
}
Rich (BB code):
'Attendance.exe': Loaded 'Z:\College\Year2\Semester 2\Programming\Attendance\debug\Attendance.exe', Symbols loaded.
'Attendance.exe': Loaded 'C:\Windows\System32\ntdll.dll', No symbols loaded.
'Attendance.exe': Loaded 'C:\Windows\System32\kernel32.dll', No symbols loaded.
'Attendance.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc80.debugcrt_1fc8b3b9a1e18e3b_8.0.50727.762_none_24c8a196583ff03b\msvcp80d.dll', No symbols loaded.
'Attendance.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc80.debugcrt_1fc8b3b9a1e18e3b_8.0.50727.762_none_24c8a196583ff03b\msvcr80d.dll', No symbols loaded.
'Attendance.exe': Loaded 'C:\Windows\System32\msvcrt.dll', No symbols loaded.
First-chance exception at 0x767c42eb in Attendance.exe: Microsoft C++ exception: std::exception at memory location 0x0012fa88..
The program '[2376] Attendance.exe: Native' has exited with code 0 (0x0).
Last edited: