Stefan
Stefan

Reputation: 1730

Automaticall replacing single catch clauses with duplicate catch clauses

Does anyone know whether there is a tool or something similar to replace single catch clauses with duplicate code within it in java with multiple catch clauses to remove duplicate code?

Context is an upgrade vom java jdk6 to 7.

Thanks and cheers, Ste

Upvotes: 0

Views: 91

Answers (1)

Ruchira Gayan Ranaweera
Ruchira Gayan Ranaweera

Reputation: 35577

I don't think there is a automatic way, You can do something like following

    try {
       // code
    } catch (Exception1 e1) {
      // caught Exception1
    } catch (Exception2 e2) {
      // caught Exception2
    }

You can change this to

    try {
       // code
    } catch (Exception1|Exception2 e) {
      // caught Exception1 or Exception2
    }

Upvotes: 0

Related Questions