#include<iostream.h>
#include<string.h>
class MyException
{
public:
char *cause;
MyException(char *in)
{
cause=new char[21];
strcpy(cause,in);
}
void printmessage()
{
cout<<"Error!"<<cause<<endl;
delete[] cause;
}
~MyException()
{
delete[] cause;
}
};
class person
{ int age;
public:
void get()
{
cout<<"Enter age:"<<endl;
cin>>age;
MyException e("Problem with age!");
if(age>100||age<0)
throw e;
else
cout<<"Correct age. : )";
}
};
void main()
{
person pe;
try
{
pe.get();
}
catch(MyException &x)
{
x.printmessage();
}
}
vc6.0编译通过,运行:当输入0-100之间的数时运行正常,当输入〉100的数时程序报错:
debug assertion failed!
program:c:/documents and settings/administor/debug/excep_test.exe
file:dbgdel.cpp
line:47
expression: _BLOCK_TYPE_IS_VAILD(pHead->nBlockUse)
不知为何出现这个错误???