You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python-level exception (PyBaseException?) cannot be directly coerced to Java-level Throwable #362
I'm not sure PyException.doRaise (exception, null, null) is 100% correct, but it seems to mostly work as a way to "coerce" a PyBaseException to a Throwable.
Proposal: make Jython coerce Python-level exceptions to Throwable automatically, as it seems to be possible in general case.
Usecase: I have a Java method that accepts a Throwable and either rethrows it (as a runtime exception if needed) on developer machines or logs and otherwise suppresses on production. The idea is to make bugs on developer machines maximally visible (hard to ignore an exception), but if it still makes it to production in non-critical code, log it, but not let it spoil the full server request.
Basically, request processing looks like this (simplified):
doRealStuff (); // any exception here (a bug) aborts request processing
try {
doLessImportantStuff (); // but exceptions here on production don't result in overall request failure
}
catch (Throwable exception) {
filterError (exception);
}
where filterError() is basically this:
if (STRICT_MODE) // i.e. development machine
throw new RuntimeException (exception);
else // i.e. production
justLogIt (exception);
Just one quick thought: Regardless how this issue moves on, your workaround should also work directly from Python, which makes it perhaps a bit more straight forward:
from PyException import doRaise
try:
_do_highlight (objects)
except Exception as exception:
ErrorUtils.filterError(doRaise(exception.getType(), exception, None))
(Disclaimer: I did not actually test this. Theoretically it should work.)
I'm not sure PyException.doRaise (exception, null, null) is 100% correct
As suggested in my code snippet, I think it should be PyException.doRaise(exception.getType(), exception, null).
Activity
Stewori commentedon Oct 29, 2024
Just one quick thought: Regardless how this issue moves on, your workaround should also work directly from Python, which makes it perhaps a bit more straight forward:
(Disclaimer: I did not actually test this. Theoretically it should work.)
As suggested in my code snippet, I think it should be
PyException.doRaise(exception.getType(), exception, null).