I'm making a c++ game gui lib and wondering when i should be throwing exceptions. Right now, for example, if I get a NULL pointer, the function silently fails. Should I instead throw an exception? Its not something that would really cause it to crash though. What are some examples of good places to throw exceptions?
thanks
The usual answer to this question is that you should only throw exceptions in 'exceptional' circumstances. But what are exceptional circumstances. Some examples:
It's generally a bad idea to throw exceptions as part of the normal flow of the application, but again it's up to you to define what the normal flow of the application is. But one way of looking at it is that your API should specify the range of valid inputs it will accept - and you shouldn't throw an exception in response to those inputs.
This topic has been covered a great deal on this site and elsewhere so a google search using your title will throw up lots more examples and comments.
With regards your specific application - maybe get a hold of the api for some other game gui libs to get a feel for how these libs work (assuming you think they are well designed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With