我调试了我的应用程序,代码在这段代码中的 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”)显示了这条消息(不是我放在那里的,它来自编译器或操作系统):
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 异常处理系统。