2
votes

I have a simple code:

#include "stdafx.h"
#include <iostream>

void foo()
{
    int* p = 0;
    *p = 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "123";
    foo();
    std::cout << "456";
    return 0;
}

Default debugging Visual studio settings. Debug -> Exceptions -> Reset all.

Result after running this code in debug configuration - i got exception Unhandled exception at 0x77d315de (ntdll.dll) in exc.exe: 0xC0000005: Access violation writing location 0x00000000. VS open file ostream, pointer stay here:

_Ostr.setstate(_State);
return (_Ostr);
} <--

Stack trace:

    ntdll.dll!_ZwRaiseException@12()  + 0x12 bytes  
    ntdll.dll!_ZwRaiseException@12()  + 0x12 bytes  
    exc.exe!std::operator<<<std::char_traits<char> >(std::basic_ostream<char,std::char_traits<char> > & _Ostr={...}, const char * _Val=0x00000000)  Line 808 + 0xf bytes    C++
>   exc.exe!wmain(int argc=0x00000001, wchar_t * * argv=0x00164810)  Line 14    C++
    exc.exe!__tmainCRTStartup()  Line 552 + 0x19 bytes  C
    exc.exe!wmainCRTStartup()  Line 371 C
    kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes    
    ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes   
    ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes    

If i set checkbox "Thrown" in Debug -> Win32 Exceptions -> C0000005 Visual Studio stopping at right place.

My colleague have same Visual Studio, Windows 7 x64 and same hardware. But his VS stopping at right place without changing exceptions settings.

What's wrong with settings of my Visual Studio?

Biggest problem - behavior with .net exceptions is not typical too. At this moment in debug mode VS just ignore almost all exceptions. Looks like i have global exception filter and all exceptions got handled. Program can run and show dialog while in release mode Catel mvvm toolkit spam me with exceptions about non registered Model and file system exceptions.

Any ideas, how can i fix it without setting "Thrown" checkbox.

[EDIT]

Ok, i found something strange. After changing Debug -> Exceptions i stopped at line with exception. But if i press Continue i'm going to the ostream file. Looks like VS debuger press "Continue" by default.

[EDIT]

First-chance exception at 0x012514cf in exc.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x773515de (ntdll.dll) in exc.exe: 0xC0000005: Access violation writing location 0x00000000.

Thats what i see in output. There is only one exception. Looks like exception was handled somehow, and then was thrown later somwhere else.

1
Pretty hard to explain. Other than that we're not looking at the real code. There is no "Line 17" in a program with 16 lines of code. - Hans Passant
Do you have optimizations turned on in your Debug build somehow? - Adam Rosenfield
Updated stack trace. Line number is now correct. - kuperspb

1 Answers

0
votes

The usual suspect: the .ncb file or .pdb or whatever are corrupt. Try wiping all the local files (solutionname.suo, solutionname.ncb, projectname.anything.user and everything in the intermediate and output directories) and check whether it helps anything.