Like this article? We recommend
Exceptions
To raise a Jython exception requires throwing the PyException class with two arguments: the actual Jython exception, and the exception message (what is referred to as the exception argument). Jython's built-in exceptions are located in the org.python.core.Py class. So, a ValueError is really a Py.ValueError.
raise ValueError, "Invalid Value"
The preceding Jython statement translates to its Java form as follows:
throw PyException(Py.ValueError, "Invalid Value")
Listing 1 uses the PyException to raise a Jython ValueError exception.