2

Python and Jython newbie here.

I am passably familiar with how to raise exceptions in normal Python.

However, in the Jython environment I find myself in (WLST), if I do:

raise Exception("hello")

...then it appears to raise a java.lang.Exception:

wls:/offline> raise Exception("hello")
Traceback (innermost last):
  File "<console>", line 1, in ?
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

java.lang.Exception: java.lang.Exception: hello
wls:/offline> 

How can I raise a Python Exception in this environment? Or, at least: why is it a java.lang.Exception that is raised here?

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127

1 Answers1

1

For posterity, I can do this:

from exceptions import Exception as PythonException

Then I can do this:

raise Exception('This will be a java.lang.Exception.')
raise PythonException('This will be a "native" Python exception.')
Laird Nelson
  • 15,321
  • 19
  • 73
  • 127