There is a for loop iterating over some components.
imagine that number of components are a lot and in one of the components an exception occurs.
I want to know which element caused this failure.
what I did(which is not advanced):
I had another variable to keep the last index. and in the exception, I printed the value according to that index
int lastIndex = 0
try {
for (element in elements) {
lastIndex ++
}
} catch (...) {
// print element[lastIndex]
}
Is there better way to achieve this?