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. Unhandled exception

Unhandled exception

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
9 Posts 5 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.
  • P Offline
    P Offline
    PankajB
    wrote on last edited by
    #1

    Hi There. How to catch exceptions occurred in DLL. For example main() { try { calling the “A.DLL” (DLL(donot know the source code) is generating unhandled exception, access violation) } catch(...) { //Source Code } } Even if I have catch(...) I am not able to catch the exeption. It says unhandled exeption..... Access violation reading.... How I do catch it in my main program so that I can terminate it properly? Thanks -PanB

    L S 2 Replies Last reply
    0
    • P PankajB

      Hi There. How to catch exceptions occurred in DLL. For example main() { try { calling the “A.DLL” (DLL(donot know the source code) is generating unhandled exception, access violation) } catch(...) { //Source Code } } Even if I have catch(...) I am not able to catch the exeption. It says unhandled exeption..... Access violation reading.... How I do catch it in my main program so that I can terminate it properly? Thanks -PanB

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

      See here[^] - always useful to try a Google search first.

      It's time for a new signature.

      P 1 Reply Last reply
      0
      • L Lost User

        See here[^] - always useful to try a Google search first.

        It's time for a new signature.

        P Offline
        P Offline
        PankajB
        wrote on last edited by
        #3

        Thanks Richard. It worked. I really working hard with Google but when was not able to get any solution, then only came for expert advice. Thanks anyway. Keep up the good work.

        L 1 Reply Last reply
        0
        • P PankajB

          Thanks Richard. It worked. I really working hard with Google but when was not able to get any solution, then only came for expert advice. Thanks anyway. Keep up the good work.

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

          Perhaps you noticed that I did not give expert advice, but found the answer through Google using the keywords "catch access violation". Really quite simple - give it a try.

          It's time for a new signature.

          1 Reply Last reply
          0
          • P PankajB

            Hi There. How to catch exceptions occurred in DLL. For example main() { try { calling the “A.DLL” (DLL(donot know the source code) is generating unhandled exception, access violation) } catch(...) { //Source Code } } Even if I have catch(...) I am not able to catch the exeption. It says unhandled exeption..... Access violation reading.... How I do catch it in my main program so that I can terminate it properly? Thanks -PanB

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            In general the best thing to do with an access violation in some DLL you don't have source code for is to crash. It's amateurish to think that catching it solves any problems. If you think about it, it's self evident:

            1. Something went wrong.
            2. The unexpected event happened part way though a sequence of steps that probably should have been atomic.

            I'll give some specific examples of the kind of problems that could occur:

            1. You were adding a node to a double-linked list when the access violation occurred. Now you have a node that is only partially linked in. Instead of crashing at the point of insertion you crash down the track when iterating over the list.
            2. The access violation happens after a call to EnterCriticalSection but before the corresponding LeaveCriticalSection. Instead of crashing at the problem location an entirely different thread now locks up.
            3. The crash was the last of a series of memory accesses of which some of the earlier ones (that didn't cause a crash) corrupted the heap. You'll now crash at some later time when allocating or freeing memory.

            You could come up with a million of these examples. In most cases "recovering" from low-level exceptions by catching them turns a bad problem into a worse one. Sometimes crashing is a feature; don't make things worse trying to "fix" things. You may already know all this (you did mention something about terminating correctly), but I thought it best to point out just in case. There's also the fact that moving the manifestation of a problem (a crash) even slightly from the source of the problem makes it many times harder to fix in future.

            Steve

            R S 2 Replies Last reply
            0
            • S Stephen Hewitt

              In general the best thing to do with an access violation in some DLL you don't have source code for is to crash. It's amateurish to think that catching it solves any problems. If you think about it, it's self evident:

              1. Something went wrong.
              2. The unexpected event happened part way though a sequence of steps that probably should have been atomic.

              I'll give some specific examples of the kind of problems that could occur:

              1. You were adding a node to a double-linked list when the access violation occurred. Now you have a node that is only partially linked in. Instead of crashing at the point of insertion you crash down the track when iterating over the list.
              2. The access violation happens after a call to EnterCriticalSection but before the corresponding LeaveCriticalSection. Instead of crashing at the problem location an entirely different thread now locks up.
              3. The crash was the last of a series of memory accesses of which some of the earlier ones (that didn't cause a crash) corrupted the heap. You'll now crash at some later time when allocating or freeing memory.

              You could come up with a million of these examples. In most cases "recovering" from low-level exceptions by catching them turns a bad problem into a worse one. Sometimes crashing is a feature; don't make things worse trying to "fix" things. You may already know all this (you did mention something about terminating correctly), but I thought it best to point out just in case. There's also the fact that moving the manifestation of a problem (a crash) even slightly from the source of the problem makes it many times harder to fix in future.

              Steve

              R Offline
              R Offline
              ramana g
              wrote on last edited by
              #6

              If you are calling DLL functions, check whether you are passing correct parameters, if any?

              S 1 Reply Last reply
              0
              • S Stephen Hewitt

                In general the best thing to do with an access violation in some DLL you don't have source code for is to crash. It's amateurish to think that catching it solves any problems. If you think about it, it's self evident:

                1. Something went wrong.
                2. The unexpected event happened part way though a sequence of steps that probably should have been atomic.

                I'll give some specific examples of the kind of problems that could occur:

                1. You were adding a node to a double-linked list when the access violation occurred. Now you have a node that is only partially linked in. Instead of crashing at the point of insertion you crash down the track when iterating over the list.
                2. The access violation happens after a call to EnterCriticalSection but before the corresponding LeaveCriticalSection. Instead of crashing at the problem location an entirely different thread now locks up.
                3. The crash was the last of a series of memory accesses of which some of the earlier ones (that didn't cause a crash) corrupted the heap. You'll now crash at some later time when allocating or freeing memory.

                You could come up with a million of these examples. In most cases "recovering" from low-level exceptions by catching them turns a bad problem into a worse one. Sometimes crashing is a feature; don't make things worse trying to "fix" things. You may already know all this (you did mention something about terminating correctly), but I thought it best to point out just in case. There's also the fact that moving the manifestation of a problem (a crash) even slightly from the source of the problem makes it many times harder to fix in future.

                Steve

                S Offline
                S Offline
                Saurabh Garg
                wrote on last edited by
                #7

                I don't completely agree. While I agree that if there is an access violation in some DLL then program is in unstable state but crashing it (and letting OS tell you that you got a bad application) is bit extreme. I believe that such cases must be detected and a meaningful error must be displayed to user before closing the application. To me such application looks more professional. -Saurabh

                S 1 Reply Last reply
                0
                • S Saurabh Garg

                  I don't completely agree. While I agree that if there is an access violation in some DLL then program is in unstable state but crashing it (and letting OS tell you that you got a bad application) is bit extreme. I believe that such cases must be detected and a meaningful error must be displayed to user before closing the application. To me such application looks more professional. -Saurabh

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  The user will be more appreciative when the bug is fixed because the crash caused a report to be sent to Windows Error Reporting[^] which was download and analysed by the software publisher. A software company that develops software but doesn't collect these reports (or use some other 3rd party system of a similar nature) is doing it wrong. In most cases a custom message will be no more "meaningful" than a crash, but a crash is more constructive (it sends an error report to MS) and the state of the program has not altered by some custom "something ain't working" error dialog (and thus making analysis harder).

                  Steve

                  1 Reply Last reply
                  0
                  • R ramana g

                    If you are calling DLL functions, check whether you are passing correct parameters, if any?

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #9

                    Can't hurt.

                    Steve

                    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