下面的程序编译成功,但无法运行并调用 abort() 函数,该函数会抛出一条消息,提示“此应用程序已请求运行时以不寻常的方式终止它。请联系应用程序的支持团队以获取更多信息。” , 为什么这样?
#include<cstring>
#include<iostream>
using std::string;
using std::endl;
using std::cout;
class ThrowException{
private:
string msg;
int b;
public:
ThrowException(string m="Unknown exception",int factor=0) throw(string); //A
};
ThrowException::ThrowException(string m, int f) throw(string):msg(m),b(f){ //B
if(b==1)
throw "b=1 not allowed.";
}
int main(){
try{
ThrowException a("There's nothing wrong.", 1);
}catch(string e){
cout<<"The address of e in catch block is "<<&e<<endl;
}
}