Topic got moved.
Was attempting code from the other thread.
Tried to delete this topic, can't.
Someone please delete.
You have colon after the except
keyword and at the end of the line. The first one doesn't belong. (And why is this in this topic?) Moved to a new topic.
from java.lang import Exception as JavaError
logger = system.util.getLogger("yourLoggerName")
try:
test = 1/0
except JavaError, je:
logger.warn("An error occurred", e)
except Exception, e:
logger.warnf("An error occurred: %s", e)
I now recommend that you use Throwable instead, all Java Exceptions are derived from the Throwable interface so it is more verbose in what it catches.
from java.lang import Throwable
logger = system.util.getLogger("yourLoggerName")
try:
test = 1/0
except Throwable, t:
logger.warn("An error occurred", t)
except Exception, e:
logger.warn("An error occurred", e)
In the snippet you've provided I do not see where you have included the import. You must import the Java Type to use it.
You cannot put jython exceptions into loggers. Use PythonAsJavaException()
to wrap them.
PythonAsJavaException
can be found in my later.py script.