Author Topic: Error handling  (Read 7775 times)

tuturto

  • Rogueliker
  • ***
  • Posts: 259
  • Karma: +0/-0
    • View Profile
    • pyherc
Error handling
« on: May 27, 2013, 09:31:40 AM »
I was playing around with error handling and started wondering how others are doing it. So far I have let the user interface to deal with them (Qt catches pretty much everything, dumps them into console and tries to continue executing the program), but it's somewhat ugly solution.

I wrote a decorator, that can handle exceptions in specific cases (Character class in this case). It wraps a function and catches all exceptions. When an exception occurs, internal clock of the character is moved forward and message is displayed "World phases out around you for a second" or "{0} is unsure about existence of world", where {0} is name of the character who is causing the error. The goal is that if there is a single character who is in broken state, the game can still continue running. Code is at https://github.com/tuturto/pyherc/blob/master/src/pyherc/data/character.py

But this only works when exception is originated from character or something called by it. Granted, most of the logic starts there I guess, but I'm still wondering if there's other options too.
Everyone you will ever meet knows something you don't.
 - Bill Nye

miki151

  • Rogueliker
  • ***
  • Posts: 264
  • Karma: +0/-0
    • View Profile
Re: Error handling
« Reply #1 on: May 27, 2013, 12:18:42 PM »
Best you can do is crash the game and let the user send a bug report automatically.
KeeperRL, Dungeon Keeper in roguelike style:
http://keeperrl.com

tuturto

  • Rogueliker
  • ***
  • Posts: 259
  • Karma: +0/-0
    • View Profile
    • pyherc
Re: Error handling
« Reply #2 on: May 28, 2013, 05:29:41 AM »
Best you can do is crash the game and let the user send a bug report automatically.

That's one option, but I rather try to fix the game state if possible. If there's a bug that rarely corrupts an item object so it could crash the game, I would rather remove the item and claim it magically disintegrated than crash the whole game. Even better would be actually fixing the item, but that's starting to get complicated.
Everyone you will ever meet knows something you don't.
 - Bill Nye

miki151

  • Rogueliker
  • ***
  • Posts: 264
  • Karma: +0/-0
    • View Profile
Re: Error handling
« Reply #3 on: May 28, 2013, 05:56:21 AM »
I know it's your game, but I'd really try to hunt these bugs instead. You won't be doing yourself a favor covering them up.
KeeperRL, Dungeon Keeper in roguelike style:
http://keeperrl.com

tuturto

  • Rogueliker
  • ***
  • Posts: 259
  • Karma: +0/-0
    • View Profile
    • pyherc
Re: Error handling
« Reply #4 on: May 28, 2013, 07:34:22 AM »
I know it's your game, but I'd really try to hunt these bugs instead. You won't be doing yourself a favor covering them up.

The point is not to cover them up, but handle them in a way that does not crash the game when they occur and at the same time record enough information that can be used to find where the problem is.

I know I'm fallible and no matter how much I try, there will be bugs in the code.
Everyone you will ever meet knows something you don't.
 - Bill Nye

daver64

  • Newcomer
  • Posts: 16
  • Karma: +0/-0
    • View Profile
    • Indigo
    • Email
Re: Error handling
« Reply #5 on: May 28, 2013, 10:52:01 AM »
If you're using c++ in QT, then you ought to find it worthwhile looking into exceptions. With a modern c++ compiler they provide a couple of benefits , namely zero overhead and less code to write for checks which makes maintenance less of a headache.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Error handling
« Reply #6 on: May 28, 2013, 03:29:43 PM »
I know I'm fallible and no matter how much I try, there will be bugs in the code.

I think it's possible to reduce the amount of bugs by learning the weak points of a programming language and preventing them from happening. At least in C++ it's quite easy actually.

loom_weaver

  • Newcomer
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: Error handling
« Reply #7 on: May 29, 2013, 03:36:26 AM »
I use two approaches.

1. I have a record feature which will help reproduce the situation
2. In the code if I hit an unexpected state I assert out.

There's no point in continuing if you hit a state you know is corrupted and/or unresolvable.  The rubicon has already been crossed.

What you described might be similar to an event driven program.  In this instance, an exception trace is dumped but the game might be able to continue on.

However, when you start trying to fix objects I wager you're entering into the realm of madness.
« Last Edit: May 29, 2013, 03:41:28 AM by loom_weaver »

tuturto

  • Rogueliker
  • ***
  • Posts: 259
  • Karma: +0/-0
    • View Profile
    • pyherc
Re: Error handling
« Reply #8 on: May 30, 2013, 06:57:38 AM »
True, fixing state sounds like a huge can of worms. It's like writing a system that can detect that there is something wrong with it and fix it, and then writing more code to do the same for the fixing system, and then for the fixing-the-fixing system...

However, I think that it makes sense to try to keep the game running even when there's a small glitch somewhere. If for nothing else than for saving the player character and giving the player a chance to start a new game with it.
Everyone you will ever meet knows something you don't.
 - Bill Nye