void (@NotNull PsiThrowStatement statement) { super.visitThrowStatement(statement); final PsiExpression expression = PsiUtil.skipParenthesizedExprDown(statement.getException()); if (!(expression instanceof PsiReferenceExpression referenceExpression)) { return; } final PsiStatement previousStatement = PsiTreeUtil.getPrevSiblingOfType(statement, PsiStatement.class); if (previousStatement != null) { return; } final PsiElement parent = statement.getParent(); if (parent instanceof PsiStatement) { // e.g. if (notsure) throw e; return; } final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiParameter parameter)) { return; } final PsiElement declarationScope = parameter.getDeclarationScope(); if (!(declarationScope instanceof PsiCatchSection catchSection)) { return; } final PsiCodeBlock block = PsiTreeUtil.getParentOfType(statement, PsiCodeBlock.class); if (block == null) { return; } final PsiElement blockParent = block.getParent(); if (blockParent != catchSection) { // e.g. if (notsure) { throw e; } return; } if (isSuperClassExceptionCaughtLater(parameter, catchSection)) { return; } final Query<PsiReference> query = ReferencesSearch.search(parameter); for (PsiReference reference : query) { final PsiElement element = reference.getElement(); if (element != expression) { return; } } final PsiTryStatement tryStatement = catchSection.getTryStatement(); registerVariableError(parameter, tryStatement); }