I was once programming an OpenGL simulation on Qt. I wanted to do a static linking to the Qt libraries, so I compiled the Qt libraries all over again but without exceptions for some reason (don't wanna go to that, that's another story).
Now the problem is, that the classes involved in the simulation have exceptions and use them. So when I compiled the program the compiler complained that I'm using exceptions while they're disabled in the compiler command-line.
I would like to find a fancy method for writing my classes, in a way that makes it possible to disable or enable exceptions according to one variable (something like a static or macro variable). So for example, I could define the value of a variable to be 1 and have exceptions (throw commands) enabled, or 0 to have them "overlooked" by the compiler and use simple C return values for debugging which is available anyway whether exceptions are enabled or not. Is that ever possible?
The problem is, that whenever the word "throw" is there in the code with exceptions disabled, the compiler complains. How get some if condition to overlook throw commands so I won't have conflicts like the one I mentioned?
throw command aside, you don't change the way you write your code. C++ exceptions are designed to cope with modules that don't support exceptions.
Now, it could be that one library is expecting a build of another that was built with exceptions one, but in they're off. So that's a legitimate complaint. But that's not a coding issue, it's a build issue.
Yes, exactly. I know it's a build issue. That's why I'm asking whether there's a way to talk to the compiler through the code, and tell it to overlook "throw" commands when some flag is there.
It's not a library issue, btw. The complaint was clearly like "throw command with exceptions disabled".
Usualy there is a macro which define if exceptions are used or not. For example it is __EXCEPTIONS on gcc.
So you can define a macro which tell if there is exception compiler independant and use it to make custom throw/try/catch blocks like this: