以下のプログラムは正常にコンパイルされますが、実行に失敗し、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;
}
}