Reputation: 110
I've got a stange situation in visual studio 2008 C++. I work on code that was originally written for visual studio 2003, where everything works well. Now, ported to VS 2008, the exception handling, which unfortuantely exists widely in the code, does not work anymore. standard code example:
try { HRESULT hr = S_OK; // do stuff... if( FAILED( hr ) ) throw hr; } catch( HRESULT hr ) { // error handling, but we never get here } catch( ... ) { // ... not even here }
Under VS 2008, no exception is encountered, but I get a crash somewhere else, indicating that the stack pointer must be screwed up. Did anybody come across this behaviour? Any help is appreciated.
Upvotes: 0
Views: 1115
Reputation: 41106
After starting the debugger, go to Debug / Exceptions, and select for which exceptions the debugger should stop when the exception is thrown.
Upvotes: 1
Reputation: 106589
I get a crash somewhere else, indicating that the stack pointer must be screwed up.
How so? The fact of a crash has nothing to do with the stack. The bigger issue here is that we don't know what "hr" was declared as. If it was declared anything other than HRESULT, the compiler does not need to catch there.
Specifically, I believe HRESULT's definition changed with VS2005 in order to support 64 bit windows. If hr is declared as something else that happened to be the same as HRESULT before, but is not after you installed the new Windows SDK, then that's a likely cause.
Can't say more without seeing more code.
EDIT: The following works correctly:
#include <iostream>
#include <iomanip>
#include <windows.h>
int main()
{
try
{
HRESULT hr = E_FAIL;
std::cout << "Inside try\r\n";
if( FAILED( hr ) )
throw hr;
}
catch( HRESULT hr )
{
std::cout << "Error:" << std::hex << (unsigned int)hr;
}
system("pause > nul");
}
We need to see more code.
Upvotes: 1