Welcome, Guest. Please login or register. Did you miss your activation email?

Poll

Exception Handling

Use exceptions
2 (18.2%)
Return boolean
9 (81.8%)

Total Members Voted: 11

Author Topic: Suggestions for SFMLTheora, sfMod, and sfMidi (Exceptions?)  (Read 12367 times)

0 Members and 2 Guests are viewing this topic.

Silvah

  • Guest
Re: Suggestions for SFMLTheora, sfMod, and sfMidi (Exceptions?)
« Reply #15 on: April 04, 2012, 08:01:43 pm »
Klaim and A.D., you're making an assumption that is wrong in my opinion, namely that the presence of exceptions implies bugs in the program.
I don't make this assumption. A healthy program to me means a program that operates in an environment sane enough to never get into the error handling code path. As such, healthiness is more a property of a given run of a program in specified environment, rather than the program itself. Therefore, my point about the exceptional code never being used anywhere in a healthy program still stands.

Or not, see here, no cost if no exception are being thrown. http://stackoverflow.com/questions/307610/how-do-exceptions-work-behind-the-scenes-in-c#307716
You missed the point, the link you provided shows precisely the zero-cost exception handling I've been talking about.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Suggestions for SFMLTheora, sfMod, and sfMidi (Exceptions?)
« Reply #16 on: April 04, 2012, 08:18:26 pm »
Then I read that wrong. Sorry!
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: Suggestions for SFMLTheora, sfMod, and sfMidi (Exceptions?)
« Reply #17 on: April 05, 2012, 08:30:03 am »
Klaim and A.D., you're making an assumption that is wrong in my opinion, namely that the presence of exceptions implies bugs in the program.
I don't make this assumption. A healthy program to me means a program that operates in an environment sane enough to never get into the error handling code path. As such, healthiness is more a property of a given run of a program in specified environment, rather than the program itself. Therefore, my point about the exceptional code never being used anywhere in a healthy program still stands.

If, when you say error, you mean unexpected error, then yes, the program should never get into the error handling code path.

However, if you meant any error, then imagine this situation: At some point, you would like to let your user select a video to play, if he selects an invalid or corrupted file, and the program is unable to load it, there you go, an error.
Does this mean that it isn't a healthy program? I don't think so.
Imagine this situation: A user downloaded your program, which includes some data files, the user accidentally deleted 1 of the data file, your program tries to load it, and error. Is it the program's fault?

In conclusion, there are errors that we should "expect", or at least not assume that it won't happen, and this is where the error code vs exceptions come in.

On a side note: sfTheora, sfMidi, and sfMod have just been released, I went with "return boolean", along with an error string. You can retrieve the error string with a function, getError(), or check if there's any error with hasError(). Since it still returns false when it fails, the only time you really have to use get/hasError() (if you don't want any unhandled errors) is after the constructor.
« Last Edit: April 05, 2012, 08:36:38 am by zorexx »

Klaim

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Suggestions for SFMLTheora, sfMod, and sfMidi (Exceptions?)
« Reply #18 on: April 05, 2012, 03:14:22 pm »
Nexus, In the link I didn't say it was my advice, but I precise that it's the reasons why the traditional game companies working with consoles forbid (or are not able to use) exceptions.
I partially agree with a lot of those reasons but I think it's a case by case basis so I do use exceptions as last resort "i don't know at all what to do here" error message, and most exceptions I handle I only log them.

But that's because I have control over the project, my projects are not cpu-bound (yet), and I'm targetting PC, not low-memory, poor latency consoles.

Now, people often say that if you compare error checking with exception, you will have the same cost, but it's beside the points: in most console games you MUST NOT have errors, you just have inputs that are predictable and you cannot allow any show-stopper problem to be perceptible by the user. The only way to do that is to have a "correct" applcation, that is really hard to do. So instead of havig the program checking errors, the programmers do it (with a QA) and the final result have no checking at all (on consoles at least).

Also, know that having exception does have a cost without even throwing anything in your program. That you want or no to pay the price of using exception is up to your specific case. When I have choice, I do, but on some hardware I can understand that it's a problem.


Finally, I suggested in the beginning of this thread to have some macro that allow the library both to provide exception and/or asserts. That way the user choose for his specific case.

Someone (I dont remember if it's in this thread or even in this forum) noticed that the new standard libraries does provide error checking as well as exceptions, because sometimes you want to check, sometimes you want to crash, and sometimes you want to never get in this case, even if it's possible.

Let the user choose. It's easy to do with macros actually.

 

anything