title: How to handle division by zero exception
body: <p>I have made a simple calculator using php, and i want to handle exception of division by zero, I am new at this and need help how to do this, if anyone can help:-
  Below is my code</p>
  
  <pre><code>&lt;?php
  
  $result = 0;
  class calculator
  {
      var $a;
      var $b;
      function checkoperation($operator)
      {
          switch ($operator) {
  
              case 'divide':
                  return $this-&gt;a / $this-&gt;b;
                  break;
  
              case 'multiply':
                  return $this-&gt;a * $this-&gt;b;
                  break;
  
              case 'add':
                  return $this-&gt;a + $this-&gt;b;
                  break;
  
              case 'subtract':
                  return $this-&gt;a - $this-&gt;b;
                  break;
          }
      }
      function getresult($a, $b, $c)
      {
          $this-&gt;a = $a;
          $this-&gt;b = $b;
          return $this-&gt;checkoperation($c);
      }
  }
  $cal = new calculator();
  if (isset($_POST['calculate_btn'])) {
      $first_num  = $_POST['first_num_txtbox'];
      $second_num = $_POST['second_num_txtbox'];
      $operation  = $_POST['operation_slctbox'];
      $result     = $cal-&gt;getresult($first_num, $second_num, $operation);
      echo "The result is: " . $result;
  }
  ?&gt;
  </code></pre>