【发布时间】:2014-06-12 09:16:08
【问题描述】:
try
{
bool numericname=false;
std::cout <<"\n\nEnter the Name of Customer: ";
std::getline(cin,Name);
std::cout<<"\nEnter the Number of Customer: ";
std::cin>>Number;
std::string::iterator i=Name.begin();
while(i!=Name.end())
{
if(isdigit(*i))
{
numericname=true;
}
i++;
}
if(numericname)
{
throw "Name cannot be numeric.";
}
} catch(string message)
{
cout<<"\nError Found: "<< message <<"\n\n";
}
为什么我收到未处理的异常错误?即使在我添加了 catch 块来捕获抛出的字符串消息之后?
【问题讨论】:
-
试试
catch (char* msg)或catch (const char* msg)之类的东西 -
(char* message) 工作! :D 但是之前的代码有什么问题?我确实添加了#include
-
非常感谢,它成功了!!
-
查看
std::string的答案
标签: c++ exception try-catch unhandled