Newbee Exception handling Guidance
-
Hi I am getting an Error First Chance Exception at xxxxx (ntdll.dll) access violation reading location 0xFFFFFFFFFFFFFFFF (running under the Visual Studio Debugger) This happens after I create a CDialog with a richedit from MAINFRAME I don't have any exception handling in my program When I look at the stack call its some where in NTDLL tracing back to Kernel32 Could someone at the very least point me to a good place for Exception handling for beginners in MFC Thanks
-
First Chance Exceptions can be benign under the debugger. Did the application crash at that point? If so, you should look at the stack trace to see what was the last line of code in your application.
-
This might not be the expected answer: With most types of exceptions the best handling is avoiding that they occur. This applies especially to the access violation exception. Even when catching it by code, the only reasonable "handling" is terminating the application immediately. In your actual case you should use the debugger stepping back in the code to find out what let the exception occur. It is probably one of your objects that hasn't been initialised or set to an error state (e.g. a pointer containing the value
-1
) and the exception is thrown when it is used the first time (inside the kernel / ntddl in your case). A general hint to reduce debugging time searching for the source of such exceptions is checking the success state of every function that provides one (usually the return value). The simplest way to do this is using assertions in debug build. With MFC you can use the ASSERT (MFC)[^] and VERIFY[^] macros. -
First Chance Exceptions can be benign under the debugger. Did the application crash at that point? If so, you should look at the stack trace to see what was the last line of code in your application.
-
I am returning to caller of SendMessage something on the stack the stack may have gotten deleted before the SendMessage completed I moved the return value to the class object So I'll see Thanks
-
Hi I am getting an Error First Chance Exception at xxxxx (ntdll.dll) access violation reading location 0xFFFFFFFFFFFFFFFF (running under the Visual Studio Debugger) This happens after I create a CDialog with a richedit from MAINFRAME I don't have any exception handling in my program When I look at the stack call its some where in NTDLL tracing back to Kernel32 Could someone at the very least point me to a good place for Exception handling for beginners in MFC Thanks
ForNow wrote:
This happens after I create a CDialog with a richedit...
Have you remembered to call
AfxInitRichEdit2()
to load the richedit library? Another option would be to temporarily add theDS_NOFAILCREATE
style to the dialog. That way it'll go ahead and create/display the dialog even if there is a problem with one or more controls. When you see what control is missing, you know where to focus your efforts."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
ForNow wrote:
This happens after I create a CDialog with a richedit...
Have you remembered to call
AfxInitRichEdit2()
to load the richedit library? Another option would be to temporarily add theDS_NOFAILCREATE
style to the dialog. That way it'll go ahead and create/display the dialog even if there is a problem with one or more controls. When you see what control is missing, you know where to focus your efforts."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I was doing sockets if my connect was good I issued A AfxMessageBox indicating success apparently that caused the problem I didn't use CWnd::MessageBox
That reminds me of a guy in college who was having trouble with his program crashing. He solved the problem by adding a few calls to
printf()
. I just sat there with a :wtf: look in my eyes."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
That reminds me of a guy in college who was having trouble with his program crashing. He solved the problem by adding a few calls to
printf()
. I just sat there with a :wtf: look in my eyes."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
:laugh: I've seen the same in assembler, "but when I put some NOP's here, it works fine!" Ugh!
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
-
:laugh: I've seen the same in assembler, "but when I put some NOP's here, it works fine!" Ugh!
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
jeron1 wrote:
"but when I put some NOP's here, it works fine!"
In some cases, that can actually be the solution. :) For example, the PC/AT was too fast for some older PC peripherals, and would cause the peripherals to crash when sending back-to-back OUT commands to the peripheral. The solution was to add a NOP between the OUTs, which slowed the operation by just the right amount.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
-
jeron1 wrote:
"but when I put some NOP's here, it works fine!"
In some cases, that can actually be the solution. :) For example, the PC/AT was too fast for some older PC peripherals, and would cause the peripherals to crash when sending back-to-back OUT commands to the peripheral. The solution was to add a NOP between the OUTs, which slowed the operation by just the right amount.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
Ok, ok you got me there :-D. We've recently run into this, where the propagation delay of HC logic was too slow for the MCU we were using, and yes we threw in some delay. In this instance though, it was old Motorola HC11, and there was a floating input and the input read would be different depending on, apparently, the instructions that were being executed just before the read.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle