How do I make VC++'s debugger break on exceptions?
I'm trying to debug a problem in a DLL written in C that keeps causing access violations. I'm using Visual C++ 2008, but the code is straight C.
I'm used to Delphi, where if an exception occurs while running under the debugger, the program will immediately break to the debugger and it will give you a chance to examine the program state. In Visual C++, though, all I get is a message in the Output tab:
First-chance exception at blah blah blah: Access violation reading location 0x04410000.
No breaks, nothing. It just goes and unwinds the stack until it's back in my Delphi EXE, which recognizes something's wrong and alerts me there, but by that point I've lost several layers of call stack and I don't know what's going on.
I've tried other debugging techniques, but whatever it's doing is taking place deep within a nested loop inside 开发者_运维知识库a C macro that's getting called more than 500 times, and that's just a bit beyond my skill (or my patience) to trace through.
I figure there has to be some way to get the "first-chance" exception to actually give me a "chance" to handle it. There's probably some "break immediately on first-chance exceptions" configuration setting I don't know about, but it doesn't seem to be all that discoverable.
Does anyone know where it is and how to enable it?
From the Debug menu, select Exceptions and check the boxes of the exceptions you'd like the debugger to break on. "Access Violation" is under "Win32 Exceptions."
You can also create a data breakpoint using the address specified in the "First-chance exception at..." line.
Following on from James' answer, the exceptions you're looking for are underneath the Win32 exceptions section. You should see Access Violation in there.
精彩评论