Answer the question
In order to leave comments, you need to log in
How to properly refactor Exceptions?
Tell me how to do the refactoring of Exceptions. For example, put it in a separate method, etc. On different sites, everyone writes differently. Point me in the right direction with a link to stackoverflow or some other answer.
Well, for example, this Exception writes to the FileWriter file, and the Exception in the finally field closes the stream.
try {
//...
} catch (FileNotFoundException e) {
//...
} catch (IOException e) {
//...
} finally {
try {
} catch (NullPointerException e) {
//...
} catch (IOException e) {
//...
}
}
Answer the question
In order to leave comments, you need to log in
Do you really have your own handler in each exception? If not, then why do you need them (except, of course, bookish truths that it’s good to do this)?
Hello.
1) Why not use try-with-resources ? This will save you from having to write extra code to close Writer.
2) Use multiple exception handling . This will avoid duplicating the processing code if it is the same.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question