Windows API functions and exceptions
When writing some code that uses the windows API heavily, I thought about creating an exception class that would give you extended error information on a function, using GetLastError and FormatMessage.
However, there is one thing I'm not sure of: Can I guarantee that no windows API function is called that calls SetLastError in between throwing the exception and handling it?
For what it's worth, I'm callin GetLastError() in the constructor of the exception class, and when I throw it, the code is pretty much like this:
I know I can modify the constructor to take the last error code as parameter to the constructor, but it somewhat defeats the convenience of the class. It's supposed to do that stuff for you.
if(WindowsAPIFunction() == BAD_RETURN_VALUE)
Any input on this will be appreciated.