C++ Exceptions & OpenGL performance

Having only just recently got the hang of exceptions, I’m keen to utilise them, but I do know that there is some performance overhead associated w/ their use.
I don’t know how much, though.
If I just ran everything in a try…catch block from the outset, would this effect speed too adversely (or at all)?
Or would peolpe reccommend using assert until I’m very confident of my code, then turning it off?
I hate passing bools everywhere, cuz I always lose track of them.
Cheers for any input,

Hi !

The use of exceptions increase the size of the executable, but as long is not exception is thrown your code should run pretty much at the same speed as without the exception code.


Thanks alot, man - I’ll get using them, then!

But be careful not to overuse them. Exceptions should be used for “exceptional” conditions – things that are supposed to work but don’t – not as a substitute for return codes. Some examples (assuming you’re developing a game):

  • If you can’t open your game’s .ini or .cfg file, that’s an exception

  • If you fail to create a rendering context in Windows, that’s an exception

  • If the player tries to open a door for the next room but it’s locked, that’s NOT an exception, it’s an expected response.

I work with Java programmers who throw exceptions around like return codes. Nothing more than a glorified “goto” if you use them that way.

Yeah - cheers, man.
I’ll only use them for major problems - good to hear a cautionary voice, nonetheless, cuz I have a lazy reflex like you wouldn’t believe.