code: def install_exception_handler():
      """
      Hook an exception handler into Py4j, which could capture some exceptions in Java.
  
      When calling Java API, it will call `get_return_value` to parse the returned object.
      If any exception happened in JVM, the result will be a Java exception object, it raise
      py4j.protocol.Py4JJavaError. We replace the original `get_return_value` with one that
      could capture the Java exception and throw a Python one (with the same error message).
  
      It's idempotent, could be called multiple times.
      """
      original = py4j.protocol.get_return_value
      # The original `get_return_value` is not patched, it's idempotent.
      patched = capture_java_exception(original)
      # only patch the one used in py4j.java_gateway (call Java API)
      py4j.java_gateway.get_return_value = patched
  
imports: import py4j
  from py4j.protocol import Py4JJavaError
label_desc: Use image node_id 2 for calling a global function with example usage: install_exception_handler() without return types