アプリケーションをデバッグすると、コード内の throw ステートメントでコードが即座にクラッシュします。
try
{
char newbuff[8];
if(strlen(cstr) > sizeof(newbuff))
{
throw BUFFER_TOO_SMALL;
}
if(strlen(cstr) == 0)
{
throw NO_CONTENT;
}
strcpy(newbuff, cstr); //Yeah yeah yeah, I know, I'm just learning
ptr = newbuff;
}
catch(int errn)
{
cout << "error: ";
if(errn == BUFFER_TOO_SMALL)
{
cout << "storage buffer too small.\n";
return 0;
}
if(errn == NO_CONTENT)
{
cout << "no content inside of buffer.\n";
return 0;
}
}
そのため、デバッグ時に throw ステートメントでクラッシュします。興味深いことに、CLI (この場合は「cmd.exe」) に次のメッセージが表示されます (これは私が入力したものではなく、コンパイラまたは OS からのものです)。
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
以前は C でプログラミングしていたので、今は C++ に傾倒しています。おわかりのように、現在、C++ が使用する try-catch 例外処理システムを管理しようとしています。