Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jpype.JException cannot print whole message in python 3.5 #328

Closed
junechen22 opened this issue Jun 8, 2018 · 2 comments
Closed

jpype.JException cannot print whole message in python 3.5 #328

junechen22 opened this issue Jun 8, 2018 · 2 comments
Assignees
Labels
bug Unable to deliver desired behavior (crash, fail, untested)

Comments

@junechen22
Copy link

when i want get JException,then run this code in python3.5 and jpype0.6.3 :

try :
        # Code that throws a java.lang.RuntimeException
except (jpype.JException(java.lang.RuntimeException),e):
            print ("Caught the runtime exception : ", JavaException.message())
            print (JavaException.stackTrace())

It throw a message :


Traceback (most recent call last):
  File "demo.py", line 67, in getTable_Query
    json_str = test.Query(self.ui.spinBox.value())
  File "D:\java_py35\connect.py", line 142, in Query
    except (jpype.JException(java.lang.RuntimeException),e):
TypeError: catching classes that do not inherit from BaseException is not allowed

if change the code like this

try :
        # Code that throws a java.lang.RuntimeException
except (jpype.JException(e)):
      print ("Caught the runtime exception : ", e)

it only print:
Caught the runtime exception : com.alipay.api.AlipayApiException

the error message is not whole message.
could anyone tell me why?

@junechen22 junechen22 changed the title jpype.JException cannot run in python 3.5 jpype.JException cannot print whole message in python 3.5 Jun 8, 2018
@Thrameos
Copy link
Contributor

There is something about JPype exceptions where they don't throw the java type but rather a class contained within it. I haven't yet puzzled out why it is constructed like that, and I have a patch to correct it but as it causes API breakage I haven't submitted it yet. I believe the issue you are having is that you are expecting the exception type to be the java exception but you get a wrapper class. You have to unwrap the wrapper class to get to the full message IIRC.

@Thrameos Thrameos self-assigned this Jul 30, 2018
@Thrameos Thrameos added the bug Unable to deliver desired behavior (crash, fail, untested) label Jul 30, 2018
@Thrameos
Copy link
Contributor

Fixed in 0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unable to deliver desired behavior (crash, fail, untested)
Projects
None yet
Development

No branches or pull requests

2 participants