void (PsiTryStatement tryStatement, String... exceptionNames) { final Project project = tryStatement.getProject(); final PsiParameter[] parameters = tryStatement.getCatchBlockParameters(); final Set<PsiType> presentExceptions = Arrays.stream(parameters).map(PsiParameter::getType).collect(Collectors.toSet()); final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); final String name = codeStyleManager.suggestUniqueVariableName("e", tryStatement.getTryBlock(), false); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); for (String exceptionName : exceptionNames) { final PsiClassType type = (PsiClassType)factory.createTypeFromText(exceptionName, tryStatement); if (presentExceptions.stream().anyMatch(e -> e.isAssignableFrom(type))) { continue; } final PsiCatchSection section = factory.createCatchSection(type, name, tryStatement); final PsiCatchSection element = (PsiCatchSection)tryStatement.add(section); codeStyleManager.shortenClassReferences(element); } }