Following is the code snippet I have written in the process of learning exception handling in C++(using visual studio 2010 compiler).
#include "stdafx.h" #include <iostream> using namespace std; void multi_double() { double first,second,product; try{ cout << "Enter the first number\n"; cin >> first; cout << "Enter the second number\n"; cin >> second; product = first * second; cout << product; } catch(...){cout << "Got an exceptional behaviour";} } void stud_age(){ int age; try{ cout << "Enter student's age\n"; cin >> age; if(age < 0) throw; cout << endl <<age; } catch(...) { cout << "Caught here\n"; } } class Model{ public: Model(){cout << "ctor\n";} ~Model(){cout << "dtor\n";} }; int _tmain(int argc, _TCHAR* argv[]) { //multi_double(); //stud_age(); int a; try{ Model obj; int *p = NULL; *p = 0;//expecting access violation exception } catch(...){ cout << "caught an exception\n"; } return 0; } Enable C++ exception is set to Yes[/EHsc]. But when I run the application,it is still crashing anyway ! with following information:
Problem signature: Problem Event Name: APPCRASH Application Name: DataTypeConversions.exe Application Version: 0.0.0.0 Application Timestamp: 4ffd8c3d Fault Module Name: DataTypeConversions.exe Fault Module Version: 0.0.0.0 Fault Module Timestamp: 4ffd8c3d Exception Code: c0000005 Exception Offset: 00001051
Why is not control coming to catch block?!