|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - recommended error handling
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? Apr 07 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? Apr 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. Apr 08 2008
|