mardi 24 novembre 2020

Java how to replace multi-level try-catch

I have a roughly similar construction:

try {
    ...some code
} catch (Exception e) {
    try {
        ...some code
    } catch (Exception ex) {
        ...another try-catch
    }
}

That is, the logic is that I need to execute the method. If an exception throws, then execute another, and so on. This code looks really bad. How can this be refactored?

Aucun commentaire:

Enregistrer un commentaire