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. try-catch handling

try-catch handling

Scheduled Pinned Locked Moved C / C++ / MFC
c++
4 Posts 4 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.
  • M Offline
    M Offline
    Mary Chennai
    wrote on last edited by
    #1

    I have a try-catch block as follows try { A(); } catch(...) { } When i was working with Visual C++ 6.0, any null pointer accessed within function A was caught by the above catch. But now after VS2005 conversion, the same catch doesn't handles null pointer access, and the program crashes. Please suggest on the Project Setting to be changed for this to work.

    R N 2 Replies Last reply
    0
    • M Mary Chennai

      I have a try-catch block as follows try { A(); } catch(...) { } When i was working with Visual C++ 6.0, any null pointer accessed within function A was caught by the above catch. But now after VS2005 conversion, the same catch doesn't handles null pointer access, and the program crashes. Please suggest on the Project Setting to be changed for this to work.

      R Offline
      R Offline
      Russell
      wrote on last edited by
      #2

      Usually YOU have to check if the pointer is valid:

      if(p!=NULL){
      ...
      p->...
      ...
      }

      in this case you also can:

      try{
      if(p==NULL) AfxThrowMemoryException();
      ....
      p->...
      ...
      }catch(...){
      }

      hope helps:)


      Russell

      1 Reply Last reply
      0
      • M Mary Chennai

        I have a try-catch block as follows try { A(); } catch(...) { } When i was working with Visual C++ 6.0, any null pointer accessed within function A was caught by the above catch. But now after VS2005 conversion, the same catch doesn't handles null pointer access, and the program crashes. Please suggest on the Project Setting to be changed for this to work.

        N Offline
        N Offline
        nbugalia
        wrote on last edited by
        #3

        From MSDN : Also, in Visual C++ 2005, all objects in scope when the asynchronous exception is generated will not be destroyed even if the asynchronous exception is handled. Under /EHs, catch(...) will only catch C++ exceptions. Access violations and System.Exception exceptions will not be caught. Resolution : You can use Yes With SEH Exceptions (/EHa) option. To set this option - Click the C/C++ folder. Click the Code Generation property page. Modify the Enable C++ Exceptions property -- modified at 5:41 Monday 24th September, 2007

        S 1 Reply Last reply
        0
        • N nbugalia

          From MSDN : Also, in Visual C++ 2005, all objects in scope when the asynchronous exception is generated will not be destroyed even if the asynchronous exception is handled. Under /EHs, catch(...) will only catch C++ exceptions. Access violations and System.Exception exceptions will not be caught. Resolution : You can use Yes With SEH Exceptions (/EHa) option. To set this option - Click the C/C++ folder. Click the Code Generation property page. Modify the Enable C++ Exceptions property -- modified at 5:41 Monday 24th September, 2007

          S Offline
          S Offline
          Signal 9
          wrote on last edited by
          #4

          ah you beat me to it X|

          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