J
J
javanub2014-07-16 11:30:26
Java
javanub, 2014-07-16 11:30:26

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

2 answer(s)
S
Sergey, 2014-07-16
@mastedm

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)?

J
Jordan GromHoll, 2014-07-24
@GromHoll

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 question

Ask a Question

731 491 924 answers to any question