RACING121 RACING121 - 6 months ago 14
Java Question

How to show dialog when lwjgl game crashes (java)

I am using LWJGL to make my new game.

Quick Question:

When my game crashes with something like this:


Exception in thread "main" java.lang.NullPointerException
at engineTester.MainGameLoop.main(MainGameLoop.java:376)
C:\Users\Kojo Ofori\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1


How do I get it to print it in dialog so that when someone runs it and it crashes they will be able to see it as a dialog that is has crashed

Hope it made sense

Answer

You can use try ...catch and catch the exception (in a baseclass / superclass), send the user an error code that he can report and log a more detailed error. Depending on your configuration:

 ...
    try {
        /* game is playing() */
    }
    catch (MyGameException gameException) {        
       logging.log(gameException.log());        
       sendErrorCodeToTheUser(gameException);        
    }
Comments