Created Tips & Tricks for working with Jython (markdown)
34
Tips-&-Tricks-for-working-with-Jython.md
Normal file
34
Tips-&-Tricks-for-working-with-Jython.md
Normal file
@@ -0,0 +1,34 @@
|
||||
## Debugging
|
||||
Debugging can be a bit special with jython/PyPluginLoader.
|
||||
|
||||
When something goes wrong, you probably see a weird traceback that's not telling you shit.
|
||||
...unless you take a closer look.
|
||||
|
||||
You will not see a direct traceback of the python methods.
|
||||
Instead, you'll probably see a bunch of java, bukkit and python things, because it tries to translate python into java, line per line.
|
||||
Take a closer look at the method names, they might tell you what it's trying to do and where it's coming from.
|
||||
|
||||
Watch out for something like `org.python.pycode._pyx5.horribleCode$23(/path/to/badcode.py:214) ~[?:?]`
|
||||
|
||||
0. In this case, `_pyx5` is our module.
|
||||
0. `horribleCode` is the method that was called
|
||||
0. `/path/to/badcode.py` is the actual file of our module
|
||||
0. `:214` is the line in which the error occured.
|
||||
|
||||
Please note that the line may not be accurate. You'll often get the start of a loop, or the end of a method - when the actual error was somewhere in there.
|
||||
|
||||
In many cases, this is enough to find your bug. If you still cannot find it,try to catch exceptions in your code, as follows:
|
||||
|
||||
|
||||
## Catching exceptions
|
||||
|
||||
If you want to catch all exceptions (e.g. for debugging), **do not `except Exception`**.
|
||||
Since we're using jython, this will not catch Java exceptions.
|
||||
Instead, use `except` and print the traceback. This will give you some more deatails:
|
||||
```python
|
||||
from traceback import format_exc as trace
|
||||
try:
|
||||
#code
|
||||
except: # everything
|
||||
print(trace())
|
||||
```
|
||||
Reference in New Issue
Block a user