code: def _check_for_exception_catch(
      node_context, jedi_name, exception, payload=None
  ):
      """
      Checks if a jedi object (e.g. `Statement`) sits inside a try/catch and
      doesn't count as an error (if equal to `exception`).
      Also checks `hasattr` for AttributeErrors and uses the `payload` to compare
      it.
      Returns True if the exception was catched.
      """
  
      def check_match(cls, exception):
          try:
              return isinstance(
                  cls, CompiledObject
              ) and cls.is_super_class(exception)
          except TypeError:
              return False
  
      def check_try_for_except(obj, exception):
          # Only nodes in try
          iterator = iter(obj.children)
          for branch_type in iterator:
              colon = next(iterator)
              suite = next(iterator)
              if branch_type == "try" and not (
                  branch_type.start_pos
                  < jedi_name.start_pos
                  <= suite.end_pos
              ):
                  return False
  
          for node in obj.get_except_clause_tests():
              if node is None:
                  return True  # An exception block that catches everything.
              else:
                  except_classes = node_context.eval_node(node)
                  for cls in except_classes:
                      from jedi.evaluate.context import iterable
  
                      if (
                          isinstance(cls, iterable.Sequence)
                          and cls.array_type == "tuple"
                      ):
                          # multiple exceptions
                          for lazy_context in cls.py__iter__():
                              for typ in lazy_context.infer():
                                  if check_match(typ, exception):
                                      return True
                      else:
                          if check_match(cls, exception):
                              return True
  
      def check_hasattr(node, suite):
          try:
              assert (
                  suite.start_pos <= jedi_name.start_pos < suite.end_pos
              )
              assert node.type in ("power", "atom_expr")
              base = node.children[0]
              assert base.type == "name" and base.value == "hasattr"
              trailer = node.children[1]
              assert trailer.type == "trailer"
              arglist = trailer.children[1]
              assert arglist.type == "arglist"
              from jedi.evaluate.arguments import TreeArguments
  
              args = list(
                  TreeArguments(
                      node_context.evaluator, node_context, arglist
                  ).unpack()
              )
              # Arguments should be very simple
              assert len(args) == 2
  
              # Check name
              key, lazy_context = args[1]
              names = list(lazy_context.infer())
              assert len(names) == 1 and is_string(names[0])
              assert (
                  force_unicode(names[0].get_safe_value())
                  == payload[1].value
              )
  
              # Check objects
              key, lazy_context = args[0]
              objects = lazy_context.infer()
              return payload[0] in objects
          except AssertionError:
              return False
  
      obj = jedi_name
      while obj is not None and not isinstance(
          obj, (tree.Function, tree.Class)
      ):
          if isinstance(obj, tree.Flow):
              # try/except catch check
              if obj.type == "try_stmt" and check_try_for_except(
                  obj, exception
              ):
                  return True
              # hasattr check
              if exception == AttributeError and obj.type in (
                  "if_stmt",
                  "while_stmt",
              ):
                  if check_hasattr(obj.children[1], obj.children[3]):
                      return True
          obj = obj.parent
  
      return False
  
imports: from parso.python import tree
  from jedi._compatibility import force_unicode
  from jedi import debug
  from jedi.evaluate.compiled import CompiledObject
  from jedi.evaluate.helpers import is_string
label_desc: Use image node_id 4 for calling a global function with example usage: _check_for_exception_catch(node_context, jedi_name, exception, payload) and returns: False, unknown, unknown, False, False, True, False, True, True, True, True