Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Newbee Exception handling Guidance

Newbee Exception handling Guidance

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiodata-structuresdebugging
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    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

    J L D 3 Replies Last reply
    0
    • F ForNow

      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

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      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.

      F 1 Reply Last reply
      0
      • F ForNow

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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.

        F 2 Replies Last reply
        0
        • L Lost User

          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.

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          It's some time after I create a CDialog with rich edit and it is displayed a few minutes after that the exception occurs I'll back tack and look at my code Thanks

          1 Reply Last reply
          0
          • J Jochen Arndt

            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.

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            Actually that was the answer I was hoping for I'll back track and look At what happened right before Thanks

            1 Reply Last reply
            0
            • L Lost User

              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.

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              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

              L 1 Reply Last reply
              0
              • F ForNow

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                If you are returning a value then it should be OK. But if it's a pointer to a stack variable then you are probably right.

                1 Reply Last reply
                0
                • F ForNow

                  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

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  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 the DS_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

                  F 1 Reply Last reply
                  0
                  • D David Crow

                    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 the DS_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

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #9

                    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

                    D 1 Reply Last reply
                    0
                    • F ForNow

                      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

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      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

                      J 1 Reply Last reply
                      0
                      • D David Crow

                        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

                        J Online
                        J Online
                        jeron1
                        wrote on last edited by
                        #11

                        :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

                        D 1 Reply Last reply
                        0
                        • J jeron1

                          :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

                          D Offline
                          D Offline
                          Daniel Pfeffer
                          wrote on last edited by
                          #12

                          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

                          J 1 Reply Last reply
                          0
                          • D Daniel Pfeffer

                            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

                            J Online
                            J Online
                            jeron1
                            wrote on last edited by
                            #13

                            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

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups