#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)
不知爲何出現這個錯誤???