C++ can't catch exception!!

I complied the code piece below successfully via VC++ 2010
but when I run the exe file ,I found there is an unhandled exception.
But I have my try catch block .why???

#include <iostream>

using namespace std;

class A
{
public:
virtual float GetSum()
{
return 0;
}
};

class B
{
private:
float sum;
public:
B(A a)
{}
B(float b)
{
sum=b*1000;
}
float GetSum()
{
return sum;
}

};

void main()
{
try
{
float f1=1.23;
int tt=f1;
cout<<"tt="<<tt<<endl;

A a;
B b=a;
B b1=1.222;

cout<<b1.GetSum()<<endl;


B *pb;
A *pa;
pa=&a;
//pb=(B*)&a;
try
{
pb=dynamic_cast<B*>(&a);
cout<<"error result:"<<pb->GetSum();
}
catch(exception& e)
{
cout<<"aaaaaaaaaaaaaaaaaaa"<<endl;
cout<<e.what()<<endl;
}
//pb=reinterpret_cast<B*>(&a);
//pb=static_cast<B*>(pa); //error
}
catch(exception& e)
{
cout<<e.what();
}


}
closed account (1vRz3TCk)
Most likely, the exception is not a C++ one, probably an access violation. Look into structured exceptions handling.
Most likely, the exception is not a C++ one, probably an access violation. Look into structured exceptions handling.


how to handle this kinds of exception?
Topic archived. No new replies allowed.