CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 23

Threaded View

  1. #12
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Regarding Exception handling

    Quote Originally Posted by LarryChen View Post
    Here is an example from you,
    Code:
    void foo()
    {
       try
       {
            char *p = 0;
            *p = 'x';.
       }
       catch(...)
       {
              // 
       }
    }
    
    int main()
    {
       try
       {
          foo();
       }
       catch (...)
       {
       }  
    }
    In the try block of function foo, no throw is thrown. So you think catch never catches any exception?
    See the first reason for a catch to be invoked. I don't know what the inner workings of the C++ SEH switch are, but there is no doubt -- the internal code is issuing a throw.

    Again, there are only three reasons why catch() becomes invoked. No other reasons exist.

    A lot of programmers believe that the catch() works by magic, and anything wrong with your program falls into the catch. Nothing can be further from the truth -- only thrown exceptions will wind up in catch blocks. Whether all SE's issues a throw, that I don't know. I showed you the code to handle the exception yourself using a handler, and then you throw from there, guaranteeing that your catch() will be invoked.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; December 27th, 2010 at 11:14 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured