Click to See Complete Forum and Search --> : First Chance Exception


Sankaran
October 18th, 2004, 02:53 AM
TMS
Hello Gurus,

I am developing a Console Application which supports MFC. Here I am using some MFC classes like CMap, CString etc.

I am using VC++ 6.0 in Windows XP.

When this application is running, I want to exit this application by pressing Ctrl+C, as we do for normal consoles. But this is craching and giving me the following message

First-chance exception <exe name> (KERNEL32.DLL):0x4010005:Control-C.

I am not getting any call stack to verify. If any body have any clue, please let me know.

Thanks in advance,
Sankaran

sbubis
October 18th, 2004, 08:07 AM
First-chance exception is a "normal" behavior. In your case it appears because you run your console application with debug mode and your program doesn't have a Ctrl-C handler.
After Ctrl-C is signaled the OS takes care to handle it (since you didn't define its handler) and you see the exception. If you continue to run your program (F5) you will be prompted to make a choice: whether to pass the exception to the program for furhter handling or not. If you choose Yes your program will end.
If you run the program without debugger you won't see the exception, rather you will see the "normal" behavior.
You can read about it, for example, in SEH (structured exception handling) topics of MSDN.
Alternatively you can use signal () function to set a Ctrl-C handler.

Mick
October 18th, 2004, 11:06 AM
TMS

First-chance exception <exe name> (KERNEL32.DLL):0x4010005:Control-C.

I am not getting any call stack to verify. If any body have any clue, please let me know.


You should be getting a stack showing the default handler.


# ChildEBP RetAddr
00 0038ffb4 7c80b50b kernel32!CtrlRoutine+0xbd (FPO: [Non-Fpo])
01 0038ffec 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])


If you want to change the behaviour of the default handler then use SetConsoleCtrlHandler(...)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolectrlhandler.asp

You can tell the debugger to ignore the first-chance CNTRL-C exception so it gets passed onto your program. Usually located under (debug->exceptions depending on your debugger of course)