title: Catching mysql connection error
body: <p>So i have simple code:</p>
  
  <pre><code>try{
      $mysqli = new mysqli($sql_login['host'], $sql_login['user'], $sql_login['password'] , $sql_login['database'], $sql_login['port'] );
  
  
      if($mysqli-&gt;connect_errno){
          throw new Exception("Failed to connect to MySQL: (" . $mysqli-&gt;connect_errno . ") " . $mysqli-&gt;connect_error);
      }
  
  }
  catch (Exception $e) {
      echo 'Exception: ',  $e-&gt;getMessage(), "\n";
  }
  </code></pre>
  
  <p>the problem is that php returns error and also the exception. Is there something like in java with throw and throws?</p>