Thread overview
recommended error handling
Apr 07, 2008
Saaa
Apr 08, 2008
lutger
Apr 08, 2008
Saaa
April 07, 2008
 I use a lot of libraries that have some kind of get_error function (eg.
glGetError).

What is the recommended way to handle errors with those kind of functions?
Maybe let them throw an exception when encountering an error and
try-catching the main?
(Like in the dsource tutorial)

How do you handle your errors?



April 08, 2008
Saaa wrote:

>  I use a lot of libraries that have some kind of get_error function (eg.
> glGetError).
> 
> What is the recommended way to handle errors with those kind of functions?
> Maybe let them throw an exception when encountering an error and
> try-catching the main?
> (Like in the dsource tutorial)
> 
> How do you handle your errors?

I always convert those errors to exceptions, if only for the reason that I
want errors to be handled in a uniform way. Take a look at this blog for a
sweet way to wrap those functions:
http://while-nan.blogspot.com/2007/06/wrapping-functions-for-fun-and-profit.html

Where you catch the exception depends on where you could handle it. For example if you can't load a texture, replace it with a standard one and go on. That might be sane or not, it depends. Thus the first question is: how critical is this Exception, should it take down the application or can I somehow repair it and go on?

It's also important to distinguish between Errors and Exceptions. Exceptions can occur in a 100% bugfree program, errors are always bugs. I don't think it's reasonable (for me at least) to only check for errors in a debug build, so with errors you might want to log them in a file before shutting down and requesting a bug report from the user in a dialog.


April 08, 2008
Thanks!

>
> I always convert those errors to exceptions, if only for the reason that I
> want errors to be handled in a uniform way. Take a look at this blog for a
> sweet way to wrap those functions:
> http://while-nan.blogspot.com/2007/06/wrapping-functions-for-fun-and-profit.html
>
> Where you catch the exception depends on where you could handle it. For example if you can't load a texture, replace it with a standard one and go on. That might be sane or not, it depends. Thus the first question is: how critical is this Exception, should it take down the application or can I somehow repair it and go on?
>
> It's also important to distinguish between Errors and Exceptions.
> Exceptions
> can occur in a 100% bugfree program, errors are always bugs. I don't think
> it's reasonable (for me at least) to only check for errors in a debug
> build, so with errors you might want to log them in a file before shutting
> down and requesting a bug report from the user in a dialog.
>
>