title: Catching Stripe errors with Try/Catch PHP method
body: <p>During my testing of STRIPE in a website, I built the code like this:</p>
  
  <pre><code>   try {
          $charge = Stripe_Charge::create(array(
            "amount" =&gt; $clientPriceStripe, // amount in cents
            "currency" =&gt; "usd",
            "customer" =&gt; $customer-&gt;id,
            "description" =&gt; $description));
            $success = 1;
            $paymentProcessor="Credit card (www.stripe.com)";
      } 
      catch (Stripe_InvalidRequestError $a) {
          // Since it's a decline, Stripe_CardError will be caught
          $error3 = $a-&gt;getMessage();
      }
  
      catch (Stripe_Error $e) {
          // Since it's a decline, Stripe_CardError will be caught
          $error2 = $e-&gt;getMessage();
          $error = 1;
      }
  if ($success!=1)
  {
      $_SESSION['error3'] = $error3;
      $_SESSION['error2'] = $error2;
      header('Location: checkout.php');
      exit();
  }
  </code></pre>
  
  <p>The problem is that sometimes there is an error with the card (not catched by the "catch" arguments I have there) and the "try" fails and the page immediately posts the error in the screen instead of going into the "if" and redirecting back to checkout.php. </p>
  
  <p>How should I structure my error handling so I get the error and immediately redirect back to checkout.php and display the error there?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>Error thrown:</p>
  
  <pre><code>Fatal error: Uncaught exception 'Stripe_CardError' with message 'Your card was declined.' in ............
  /lib/Stripe/ApiRequestor.php on line 92
  </code></pre>