try/catch LWJGL exception

Started by Hanksha, May 09, 2014, 23:54:19

Previous topic - Next topic


I've been doing a simple error log for my game, basically when an exception is catch it writes down the traces on a log .txt file.
It works fine with java exception (like IO etc...) but it seems that my try/catch don't catch the LWJGL exceptions (it actually print the trace in the console).
I think I'm missing something here. (I don't show code since it's just a try catch)
Any idea?


Its probably caused by the flying spaghetti monster. You have to sacrifice some goats in order to fix it.

Or maybe, you just show us the code you used so we can give you any useful advice instead of speculations.


Ahah, as I said i'm just talking of a simple:
  //GL stuff 
catch(LWJGLException e){
  //handle exception

For example:
try {
  System.out.println("Number of controller: " + Controllers.getControllerCount());
} catch (LWJGLException e) {

So be clear, if I do that kind of try/catch:
try {
bw = Files.newBufferedWriter(errorLog.toPath(), charset, op);
for(StackTraceElement trace: error){
} catch (IOException e) {

"Yeah!" will print, but when I do the same with lwjgl methods and I do exception on purpose it will not.


In your example you use System.out for your output stream.
Are you sure that your "ErrorLog" uses the same stream to write its data to?


The problem is not what is inside the the catch where I handle an exception. (cause it works fine with simple java exceptions)
What I am saying is that when I'm using lwjgl methods what I write in the catch (whatever it is) is not read; maybe it is handle by a try catch inside the method itself, is there a way to overwrite that?


I don't realy understand ; i already made some kind of error management. My error management is working as a thread : All thrown exceptions are catched by a catch(Exception e) so i can after call my CrashReporter.instance.generateNewCrashReport. In all cases the LWJGLException is correctly working, maybe you're not using it right... If you want i can give you a code example that is working :
        try {
            if (isWindowed){
                Display.setDisplayMode(new org.lwjgl.opengl.DisplayMode(sizeX, sizeY));
            } else {
  "Starting LWJGL - OpenAL...");
  "LWJGL - OpenAL successfully started !");
            ByteBuffer[] shit = new ByteBuffer[2];
            if (getIconPackage() == null) {
                shit[0] = renderEngine.mountTexture(SLDTGame.class.getResourceAsStream("icon16.png"));
                shit[1] = renderEngine.mountTexture(SLDTGame.class.getResourceAsStream("icon32.png"));
            } else {
                shit[0] = renderEngine.mountTexture(ClassLoader.getSystemResourceAsStream("./" + getIconPackage() + "/gameIcon16.png"));
                shit[1] = renderEngine.mountTexture(ClassLoader.getSystemResourceAsStream("./" + getIconPackage() + "/gameIcon32.png"));
            //Mouse.setNativeCursor(new org.lwjgl.input.Cursor(16, 16, 0, 0, 1, getHandMousePointer(), null));
            while (!Display.isCloseRequested()){
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                for (int j = 0; j < gameTimer.elapsedTicks; j++) {

        } catch (Exception e){

Imagine that this function is called like in a thread named "GameName" - Main Thread This is the thread of OpenGL. When something in the game code is generating an exception, the exception is always catched by onGameCrash(e). This function is part of my game engine it's called at every thrown exception, you can do whatever you want with that.
If you want to know more, i can tell you that onGameCrash will call an ExceptionHandler interface that the game must have implemented.
For Exaple :
package fr.scrable.main;

import fr.sldt.gameEngine.ExceptionHandler;

public class ScrableGameExceptionHandler implements ExceptionHandler{
    public void handleException(Exception e) {

This is the code witch will be called at every exception thrown. In my case i just print the exception and i simple hard close the game, like CTRL + ALT + SUPPR...

Hope i helped you,


Maybe that's the problem, I should put it in another thread.


Catching exception e is not very good, its always good to know exactly what is going on and to then determine what to do ad to have the full stack trace when investigating. java.util.Logger is a very simple way to catch exceptions and log them (a simple version of Log4j)

I'm not sure why your code is not picking up the exception, it would be useful to see how you are faking an exception being thrown.


That was only an example ! The perfect working system with error detection is on my other game BrickBroken. Actualy these codes are from my ScrableGame. And please not say that i'm not using loggers !
If you want to know, my game engine itself can not instanciate without the logger ! I'm setting up a logger from java.util that will log all the game infos to a log list (to be used for in-game console, saving purposes). In plus the System.out and System.err are redirected to a special class that is redirecting printings to a for out and Logger.severe for err.
For the moment error detecting is not realy my first point for me error detecting is a "feature" not a massive importent gameplay way. So in first i will make a working video scrable game and after i will make a better error detection.
I will say you something that can explain why you're not understanding correctly : i'm not english, i never never seen any english place. I would like to visit london or USA. But i can't because of money problem. I think you can see that by my email extention (contact@stonelins.FR). Yes, that's the case, i'm french. I'm just someone who hates french and loves english as much as i only play on english game servers. I'm lassed of french game servers. I hate there new way of "You pay 10â,¬ and you can play on the server". Do you realy think i can give 10â,¬ to play on a game server ? In plus of having bought the game at some 30â,¬ ?
Well, said that, now you can see better my problem i hope.


Maybe just as an idea, still have your error logger to log.txt, but also redirect you error stream to a file like so:

System.setErr(new PrintStream(new FileOutputStream("log.txt")));

This won't be as good though... But it catches all errors
Also a tip, when making a game which has error logging like yours, its a good idea to have info like Operating System, Java Version and OpenGL version.
A word used by programmers when they do not want to explain what they did.

WEE :)