When handling c++ iterator, try cath exception is not working.
Junyoung Lee
1
Reputation point
I am new to c++. And I am making a qt program using c++.
In the code below, a try catch statement is used to handle an exception that exceeds the index of the list when processing the loop.
However, when an error occurs in the try statement, it cannot be caught and an error is raised and the program ends. Can you tell me what's wrong with my code?
QListWidget* returnListWidget(list<QListWidget*> srclist, int num) {
try {
list<QListWidget*>::iterator iter = srclist.begin();
advance(iter, num);
//error occur
QListWidget* q = *iter;
return q;
}
catch (...) {
qDebug() << "helo";
return NULL;
}
}
Developer technologies | C++
3,973 questions
Sign in to answer