void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { if (element instanceof PsiExpression expression) { CodeBlockSurrounder surrounder = CodeBlockSurrounder.forExpression(ExpressionUtils.getTopLevelExpression(expression)); if (surrounder == null) return; element = surrounder.surround().getAnchor(); } else { element = CommonJavaRefactoringUtil.getParentStatement(element, false); if (element == null) return; } TextRange range = null; try{ JavaWithTryCatchSurrounder handler = new JavaWithTryCatchSurrounder(); range = handler.doSurround(project, element.getParent(), new PsiElement[]{element}); } catch(IncorrectOperationException e){ updater.cancel(JavaBundle.message("surround.with.try.catch.incorrect.template.message")); } if (range != null) { updater.select(range); } }