code: def convert_py4j_exception(e: Py4JJavaError) -> JavaException:
      """
      Convert Py4J exception to JavaException.
      """
      s = e.java_exception.toString()
      for exception in exception_mapping.keys():
          if s.startswith(exception):
              return exception_mapping[exception](
                  str(e).split(": ", 1)[1]
              )
      else:
          return JavaException(str(e).split(": ", 1)[1])
  
imports: import py4j
  from py4j.protocol import Py4JJavaError
label_desc: Use image node_id 4 for calling a global function with example usage: convert_py4j_exception(e) and returns: JavaException, exception_mapping