Replace catch(Exception) with specific declared exceptions thrown in the try block

MSAL

Replaces catch(Exception e) blocks with a multi-catch block (catch (SpecificException1 | SpecificException2 e)) containing only the exceptions declared thrown by method or constructor invocations within the try block that are not already caught by more specific catch clauses. Catching a broad Exception type can unintentionally swallow runtime exceptions that indicate programming errors, making bugs harder to detect and diagnose.

org.openrewrite.staticanalysis.OnlyCatchDeclaredExceptions
mod run . --recipe=org.openrewrite.staticanalysis.OnlyCatchDeclaredExceptions

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.