Hello Folks:
Developing in Windows 10 Pro.
I'm not a beginner, but I haven't done much with writing my own exceptions.
I'd like to catch exceptions from improper use of iterators.
Here is a piece of code that doesn't properly initialize an iterator.
An exception is thrown when I try to test this iterator against the end of a list.
Windows pops up the following Exception Unhandled window:
---------------------
Unhandled exception at 0x0F25ED76 (ucrtbased.dll) in net_results.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.
---------------------
The execution stops.
I'd like to handle the exception and continue with program execution.
I wrap the code that causes the window to pop up in a try - catch clause but the window pops up and the execution stops anyway.
How would I catch an exception in the following flawed function?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
typedef std::list <int> INT_LIST_TYPE;
void iterator_exception_test()
{
INT_LIST_TYPE::const_iterator int_iterator;
INT_LIST_TYPE int_list;
try
{
if (int_iterator == int_list.end())
{
int test_x = 0;
}
else
{
int test_x = 0;
}
}
catch (...)
{
int test_x = 0;
}
}
|