diff --git a/ixmp/backend/jdbc.py b/ixmp/backend/jdbc.py index 637783bd1..2305bd834 100644 --- a/ixmp/backend/jdbc.py +++ b/ixmp/backend/jdbc.py @@ -52,7 +52,6 @@ "at.ac.iiasa.ixmp.objects.Scenario", "at.ac.iiasa.ixmp.Platform", "java.lang.Double", - "java.lang.Exception", "java.lang.Integer", "java.lang.NoClassDefFoundError", "java.lang.IllegalArgumentException", @@ -147,7 +146,7 @@ def _handle_jexception(): """Context manager form of :func:`_raise_jexception`.""" try: yield - except java.Exception as e: + except jpype.JException as e: _raise_jexception(e) @@ -708,10 +707,18 @@ def get(self, ts): # either getTimeSeries or getScenario method = getattr(self.jobj, "get" + ts.__class__.__name__) - # Re-raise as a ValueError for bad model or scenario name, or other - with _handle_jexception(): + # Re-raise as a ValueError for bad model or scenario name, or other with + # with _handle_jexception(): + try: # Either the 2- or 3- argument form, depending on args jobj = method(*args) + except SystemError: + # JPype 1.5.0 with Python 3.12: " returned a result with an exception set" + # At least transmute to a ValueError + raise ValueError("model, scenario, or version not found") + except BaseException as e: + _raise_jexception(e) self._index_and_set_attrs(jobj, ts) @@ -728,7 +735,7 @@ def check_out(self, ts, timeseries_only): def commit(self, ts, comment): try: self.jindex[ts].commit(comment) - except java.Exception as e: + except jpype.JException as e: arg = e.args[0] if isinstance(arg, str) and "this Scenario is not checked out" in arg: raise RuntimeError(arg)