title: How to catch cURL errors in PHP
body: <p>I am using <a href="https://php.net/manual/en/ref.curl.php" rel="noreferrer">PHP <code>curl</code> functions</a> to post data to the web server from my local machine. My code is as follows:</p>
  <pre><code>$c = curl_init();
  curl_setopt($c, CURLOPT_URL, $url);
  curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($c, CURLOPT_POST, true);
  curl_setopt($c, CURLOPT_POSTFIELDS, $data);
  $result = curl_exec($c);
  if (curl_exec($c) === false) {
      echo &quot;ok&quot;;
  } else {
      echo &quot;error&quot;;
  }
  curl_close($c);
  </code></pre>
  <p>Unfortunately I am not able to catch any errors like 404, 500 or network failure. So how will I get to know that data was not posted to or retrieved from the remote?</p>