Answer the question
In order to leave comments, you need to log in
Is it possible to return to a try block after an exception has been handled?
There is a file from which values are read in turn. It is necessary to take all the data from there and then convert it to the int type. Some data is incorrect, for example contains text. I need to skip this text and then read only int. And count the number of errors separately. Is it possible to return to the try block after handling an exception for an incorrect type?
Answer the question
In order to leave comments, you need to log in
You cannot return to the try block after handling the exception. In your case, you need to do something like this:
// loop through the processing of all data blocks
try {
// processing one block, for example, type conversion
}
catch(Exception) {
// add the unprocessed block to the list of errors
continue; // to the next iteration of the loop
}
and then to the next iteration of the loop
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question