As I become more familiar with Jython and thinking like a Jython/Java
developer as opposed to a Python/C developer, it occurs to me (with a
shock of blinding obviousness (*)) that there is another way to approach
the situation of getting a Jython sys.excepthook function to be called for
Swing exceptions. And that is to use only Jython code to set up the
machinery inside the JVM to do this.
So, for example, I know I can do this in Jython:
from java.lang import System
So, this can address at least the issue of whether there needs to be a
global flag; there does not need to be a flag except as a convenience
since someone could just instead put these two lines of code in their
Jython program -- if there was a class that could be set as the second
argument. I just tried this on my system using the stock Jython2.1 jar and
it actually worked -- because I also still had the patched Jython from CVS
in the path after it -- so I think Java looked around and still found my
added class, even though it was running the unpatched Jython version.
After I removed that project from the class path, the regular exception
handler was called and my custom one was not, giving me more confidence
that is what happened.
So, while I haven't tried this yet, I think I could possibly compile that
one class, AwtExceptionHandler and have it in a jar file in my path, and
otherwise use an unpatched Jython version. But I don't want to bother
trying that if I could do something easier.
So, ideally I would like the AwtExceptionHandler class to be written in
Jython too. So, then this becomes more a Jython user question, but what
package in the second argument could I specify to System.setProperty() for
a Jython class in a Jython MyCode.py file to be able to do this? If there
is an answer, then anyone could catch Swing exceptions with just a few
lines of Jython added to their Jython projects.
(*) It might have helped that I just spent hours figuring out how to get a
JTextPane to do a client side (no server) callback to Jython on an HTML
Form submit. Definitely gave me a better appreciation for how Jython and
Java can work together.