How to catch and log NULL pointer exception in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zahidkhan
    New Member
    • Sep 2006
    • 22

    How to catch and log NULL pointer exception in C++

    Hi All,

    Plz help me if you can.....

    I have a program something like this
    int main(int argc,char* argv[])
    {
    try
    {
    int* p = NULL;
    int i = *p;
    }
    catch(int* ptr)
    {
    cout<<"Caught Null pointer Exception\n";
    }
    catch(...)
    {
    cout<<"Caught an Exception\n";
    }
    return 0;
    }
    Result of this program is
    "Caught an Exception"
    But i was expecting "Caught Null pointer Exception"

    Now plz tell me how to know in which line exception occured and which exception occured

    Eagerly waithig for your reply..........
  • Emrah KAYA
    New Member
    • Aug 2010
    • 1

    #2
    I am using the method described here: http://www.codeproject.com/KB/cpp/exceptionlogging.aspx

    Comment

    Working...