關於異常的小程序出現debug assertion failed!錯誤的原因是什麼?

#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)

不知爲何出現這個錯誤???

 

發佈了28 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章