Search code examples
c++codelite

What error in my code I have which cause exceptions ignored?


I am Implementing some program error exception catching and it's not getting to work properly thus I have seen any error in my code and compiler is also not showing any warnings and error. The programs build successfully but ignored the exceptions.

#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;
}

Solution

  • correct the following

    void programErrorExceptions()
    {
       void wrongUsage();
    }
    

    to

    void programErrorExceptions()
    {
       wrongUsage();
    }