title: C++ Error handling and exceptions (situations where they could be useful)
body: <pre><code>int main() 
  {
      try
      {
          int a = 1;
          int b;
          cin &gt;&gt; b;
          if (b &lt;= 0) throw b;
          int c = a / b;
          cout &lt;&lt; c;
          
      }
      catch (int c)
      {
          cout &lt;&lt; &quot;You can't divide by zero.&quot;;
      }
  }
  </code></pre>
  <p>Okay so I'm just now learning about error handling a bit and exceptions and well obviously here an exception is unnecessary right? I could also just put put some stuff in an if statement and else statement and that would also work wouldn't it? So I just wanted to ask does anybody have an example where it would be better to deal with errors with exceptions?
  And another tiny question, I threw b here but would it be better to just make up some integer and consider that like the error code for this specific situation? Or what exactly should I be throwing? I guess if I wanna use the value that caused an error I should probably throw that?</p>