Error Handeling

Normally i’m very diligent in my error handeling… but this is because most of my coding is done in the business world where errors often result in situations where life pretty much continues and retrying is occasionally a valid approach… or if not possible someone needs to know how to solve the error right now.

so now my question…

im finding that most of the errors that i may have to account for my game coding are in fact show stoppers. Cant load my texture file… or my shader… ya… then i really dont think we should continue. Lets stop here tell you about the problem and call it quits.

but if this is truely the case then i could just let these bubble up and handle then at my game engine layer as one catch, show error and end game.

how do you handle errors?

j.

I’m not sure about what you’re asking exactly, but I assume you’re having trouble handling OpenGL errors. They’re quite tricky to handle. Here’s something that you can put in your game loop though:


if (GL11.glGetError() != GL11.GL_NO_ERROR) {
    // throw exception or print and exit
}

Let me attempt to be more clear.

Its the old bubble up debate.

When you encounter JAVA exception that need to be handled in your code. ( which hopefully you wont have too many instance of )
Do you

A) wrap a try catch block around it and do you best to handle / hide the errors if any occur

or

b) let them bubble up and just have a high level try catch handle them since in just about every case if an error happens in a game we are not going to try to handle them gracefully but rather show an error and end the game.

When something fails, you have, I think, the following possibilities to react:

  1. Recover (restart, reload, reconnect, etc.),
  2. fallback (try again with default values, default renderer, etc.),
  3. log the failure for future improvement,
  4. do nothing.

In my private projects I don’t have time to develop recovery strategies or implement alternative engines or offer alternative servers. My projects are small. I also don’t expect the user to send me the error log. So I choose number 4 and rely more on testing.

To answer your question, I print the exceptions when they happen:

void foo() {
  try {
    // read from a file or similar
  } catch(Throwable t) {
    t.printStackTrace();
  }
}