Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a runnable jar, when crash doesn't happen in debugger?

Tags:

java

slick2d

When I debug the game in eclipse the game works fine. However, when I make runnable jar out of it the game crashes when enemy gets hit, the rest of the game works fine except that part. What do I do, how do I debug runnable jar?

like image 833
Matthew Avatar asked Mar 24 '23 07:03

Matthew


1 Answers

Put a try/catch around the function where an enemy gets hit. In the catch statement, have it print a stack trace and information on the exception caught.

Something like:

try {
   enemyHit();
} catch (Exception e) {
    System.out.print("RuntimeException: ");
    System.out.println(e.getMessage());
    e.printStackTrace();
}

Run the jar from the command line so that the printouts are still there when the jar crashes. Alternatively, write the error information to a file.

You can put the try/catch further up the stack if this doesn't catch anything. If you're not catching exceptions anywhere else, you can put this try catch all the way at the top of your stack surrounding your main loop.

I wouldn't recommend keeping the try/catch in your release code if you're fairly sure the bug is solved. There are performance issues associated with try/catch that will slow down your game if you have them surrounding frequently accessed functions.

like image 91
House Avatar answered Apr 18 '23 12:04

House