title: I am trying to throw an exception from another function, but it crashes and gives me unhandled exception. What should I do instead? c++
body: <code>
  //checks every turn whether player 1 or player 2 wins using switch and case method
  <pre><code>void caseCheck()
  {
      //when a player wins
      if (x == &quot;O&quot; &amp;&amp; y == &quot;O&quot; &amp;&amp; z == &quot;O&quot; || a == &quot;O&quot; &amp;&amp; b == &quot;O&quot; &amp;&amp; c == &quot;O&quot; || d == &quot;O&quot; &amp;&amp; e == &quot;O&quot; &amp;&amp; f == &quot;O&quot; || x == &quot;O&quot; &amp;&amp; a == &quot;O&quot; &amp;&amp; d == &quot;O&quot; || y == &quot;O&quot; &amp;&amp; b == &quot;O&quot; &amp;&amp; e == &quot;O&quot; || z == &quot;O&quot; &amp;&amp; c == &quot;O&quot; &amp;&amp; f == &quot;O&quot; || x == &quot;O&quot; &amp;&amp; b == &quot;O&quot; &amp;&amp; f == &quot;O&quot; || z == &quot;O&quot; &amp;&amp; b == &quot;O&quot; &amp;&amp; d == &quot;O&quot;)
      {
          system(&quot;cls&quot;);
          mainBoard();
          cout &lt;&lt; endl &lt;&lt; &quot;player 2 wins&quot;;
          throw; // here is where the error is
      }
      if (x == &quot;X&quot; &amp;&amp; y == &quot;X&quot; &amp;&amp; z == &quot;X&quot; || a == &quot;X&quot; &amp;&amp; b == &quot;X&quot; &amp;&amp; c == &quot;X&quot; || d == &quot;X&quot; &amp;&amp; e == &quot;X&quot; &amp;&amp; f == &quot;X&quot; || x == &quot;X&quot; &amp;&amp; a == &quot;X&quot; &amp;&amp; d == &quot;X&quot; || y == &quot;X&quot; &amp;&amp; b == &quot;X&quot; &amp;&amp; e == &quot;X&quot; || z == &quot;X&quot; &amp;&amp; c == &quot;X&quot; &amp;&amp; f == &quot;X&quot; || x == &quot;X&quot; &amp;&amp; b == &quot;X&quot; &amp;&amp; f == &quot;X&quot; || z == &quot;X&quot; &amp;&amp; b == &quot;X&quot; &amp;&amp; d == &quot;X&quot;)
      {
          system(&quot;cls&quot;);
          mainBoard();
          cout &lt;&lt; endl &lt;&lt; &quot;player 1 wins&quot;;
          throw; // here is where the error is
      }
  }
  
  //prints X to current players desired spot with user input
  void exes()
  {
      caseCheck();
      mainBoard();
      cout &lt;&lt; endl &lt;&lt; &quot;Player 1: pick a number of where you would like to go &quot;;
      cin &gt;&gt; currentMove;
      system(&quot;cls&quot;);
      if (cin.fail())
      {
          cin.clear();
          cin.ignore();
          mainBoard();
          cout &lt;&lt; endl &lt;&lt; &quot;cannot enter letter values&quot; &lt;&lt; endl;
          exes();
      }
      switch (currentMove)
      {
          case 1:
              //run check function for already inputted values
              x = &quot;X&quot;;
              movesMade[0] = 1;
              break;
          case 2:
              y = &quot;X&quot;;
              movesMade[1] = 2;
              break;
          case 3:
              z = &quot;X&quot;;
              break;
          case 4:
              a = &quot;X&quot;;
              break;
          case 5:
              b = &quot;X&quot;;
              break;
          case 6:
              c = &quot;X&quot;;
              break;
          case 7:
              d = &quot;X&quot;;
              break;
          case 8:
              e = &quot;X&quot;;
              break;
          case 9:
              f = &quot;X&quot;;
              break;
          default:
              mainBoard();
              cout &lt;&lt; endl &lt;&lt; &quot;number is not located on tic tac toe board, try again&quot; &lt;&lt; endl;
              exes();
              break;
      }
  }
  
  //prints O to current players desired spot with user input
  void oes()
  {
      caseCheck();
      mainBoard();
      cout &lt;&lt; endl &lt;&lt; &quot;Player 2: pick a number of where you would like to go &quot;;
      cin &gt;&gt; currentMove;
      system(&quot;cls&quot;);
      if (cin.fail())
      {
          cin.clear();
          cin.ignore();
          mainBoard();
          cout &lt;&lt; endl &lt;&lt; &quot;cannot enter letter values&quot; &lt;&lt; endl;
          oes();
      }
      switch (currentMove)
      {
          case 1:
              x = &quot;O&quot;;
              break;
          case 2:
              y = &quot;O&quot;;
              break;
          case 3:
              z = &quot;O&quot;;
              break;
          case 4:
              a = &quot;O&quot;;
              break;
          case 5:
              b = &quot;O&quot;;
              break;
          case 6:
              c = &quot;O&quot;;
              break;
          case 7:
              d = &quot;O&quot;;
              break;
          case 8:
              e = &quot;O&quot;;
              break;
          case 9:
              f = &quot;O&quot;;
              break;
          default:
              mainBoard();
              cout &lt;&lt; endl &lt;&lt; &quot;number is not located on tic tac toe board, try again&quot; &lt;&lt; endl;
              oes();
              break;
      }
  }
  
  int main()
  {
      try
      {
          for (int i = 0; i &lt; 4; i++)
          {
              cout &lt;&lt; player;
              exes();
              oes();
          }
          exes();
          mainBoard();
          cout &lt;&lt; &quot;Tie game&quot;;
          throw(player);
      }
      catch (...)
      {
          return 0;
      }
  }
  </code></pre>
  </code>
  in the function caseCheck, I am trying to throw an exception into the main function so I can stop the program. I tried putting exit there or return there, but it didn't do anything and the function continued running. The program does stop like it's supposed to, but it crashes right after giving me an unhandled exception error. What should I do? How should I approach this differently?