Return the actual Java Exception object on Exception?
See original GitHub issueHi!
Just wondering, I couldn’t seem to be able to get the actual Java Exception object returned as an Exception? Is this by design, or is this something that could be part of future features?
For example, it would be nice to be able to do:
MyException = jnius.autoclass("myjavaprogram.exceptions.MyException")
MyClass = jnius.autoclass("myjavaprogram.MyClass")
try:
MyClass.doSomethingThatThrowsAnException()
except MyException:
# Do something
pass
except JavaException:
# Do something else
pass
As an addendum, MyException would also have to inherit from jnius.JavaException
<bountysource-plugin> --- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/30741053-return-the-actual-java-exception-object-on-exception?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github). </bountysource-plugin>Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
java - How to return a list of objects along with Exception
In this case, the method returns the list of valid student information. But in case of an Exception, I'm not able to find...
Read more >Return Statement in Try-Catch - Java Exception Handling ...
In a try-catch-finally block that has return statements, only the value from the finally block will be returned. When returning reference types, be...
Read more >Java Exception Handling: How to Specify and ... - Stackify
When a method throws an exception object, the runtime searches the call stack for a piece of code that handles it. I will...
Read more >Exception Handling in Java - DigitalOcean
Java creates an exception object when an error occurs while executing a statement. The exception object contains a lot of debugging information ...
Read more >Best Practice: Catching and re-throwing Java Exceptions - IBM
Customers often have general catch blocks in Servlets, MDBs, EJBs and other core components where they catch all un-handled exceptions and re- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got it - thanks! It would be nice if the message included the method name, since it must be known.
I was able to print the stack trace with
and sorted it out.
(The confusion was that the code had something like
foo.bar(a.getX(), a.getY(), ...)
wherefoo
anda
are Java objects. I assumed the problem was somewhere down infoo.bar
and only later realized that it wasn’t getting that far. Debugging this interlanguage stuff can be a headache so more info in exceptions helps!)i would assume there https://github.com/kivy/pyjnius/blob/master/jnius/jnius_export_class.pxi#L831-L836
which would mean the error didn’t happen in java, it happened in python before the call to the java function, so there is no java stacktrace to report.
edit: the latter part of the message (after “got {one}”) was added in the latest version of pyjnius, released last weekend, which also solved some bugs in the lookup of methods, you might want to upgrade and try with that version.