我的代码中有什么错误会导致异常被忽略?
What error in my code I have which cause exceptions ignored?
我正在实施一些程序错误异常捕获,但它无法正常工作,因此我发现我的代码中有任何错误,编译器也没有显示任何警告和错误。
程序构建成功,但 忽略 异常。
#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();
}
我正在实施一些程序错误异常捕获,但它无法正常工作,因此我发现我的代码中有任何错误,编译器也没有显示任何警告和错误。 程序构建成功,但 忽略 异常。
#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();
}