问题描述
我正在实现一些程序错误异常捕获,并且无法正常工作,因此我在代码中看到任何错误,并且编译器也未显示任何警告和错误。 程序构建成功,但忽略 例外。
#include <iostream>
#include <string>
using namespace std;
void wrongUsage()
{
bool erroCode = true;
bool errorMessge = true;
bool stringError = true;
if(erroCode)
{
throw 7;
}else if (errorMessge)
{
throw "Something went wrong in Character message";
}else if(stringError)
{
throw string ("Something else wrong happened in the string area");
}
}
void programErrorExceptions()
{
void wrongUsage();
}
int main()
{
try {
programErrorExceptions();
}
catch (int err)
{
cout << "Code Exception occurred: " << err << '\n';
}
catch (char const *err)
{
cout << "Msg Exception occurred: " << err << '\n';
}
catch (string &err)
{
cout << "Strmsg Exception occurred: " << err << '\n';
}
return 0;
}
解决方法
更正以下内容
void programErrorExceptions()
{
void wrongUsage();
}
到
void programErrorExceptions()
{
wrongUsage();
}