V
V
Vladislav Kolotsei2015-11-04 16:11:52
Java
Vladislav Kolotsei, 2015-11-04 16:11:52

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

2 answer(s)
S
Sergei Borisov, 2015-11-04
@vlady_32

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

M
MiiNiPaa, 2015-11-04
@MiiNiPaa

Loop around try-catch block won't help?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question