private static boolean isExceptionUsed(PyExceptPart node, String text) {
      Stack<PsiElement> stack = new Stack<>();
      PyStatementList statementList = node.getStatementList();
      for (PyStatement st : statementList.getStatements()) {
        stack.push(st);
        while (!stack.isEmpty()) {
          PsiElement e = stack.pop();
          if (e instanceof PyReferenceExpression ref) {
            PsiElement resolved = ref.getReference().resolve();
            if (resolved != null) {
              if (text.equals(resolved.getText())) {
                return true;
              }
            }
          }
          for (PsiElement psiElement : e.getChildren()) {
            stack.push(psiElement);
          }
        }
      }
      return false;
    }
private static boolean isExceptionUsed(PyExceptPart node, String text)