title: Symfony internal server error when Stripe api throws exception
body: <p>I'm testing making payments using the <a href="https://stripe.com/docs/api/php#create_charge" rel="nofollow">Stripe api</a> in the Symfony framework.</p>
  
  <p>Currently when I make a legitimate call payment is made and Stripe returns a <code>status 200</code>.</p>
  
  <p>The problems start when I use one of the <a href="https://stripe.com/docs/testing" rel="nofollow">test cards</a> (or just a made up one) to force Stripe to return an error, card has expired for example, and an exception is thrown (<code>Stripe_CardError</code>). The response code from the api is <code>402</code> but even when I put a catch block in for that exception Symfony throws a <code>500 internal server error</code>.</p>
  
  <p>Here's part of the code:</p>
  
  <pre><code>require_once('../vendor/stripe/stripe-php/lib/Stripe/Stripe.php');
  
              try{           
                  \Stripe::setApiKey($this-&gt;container-&gt;getParameter('stripe_api_key'));
                  $charge = \Stripe_Charge::create(array( 
                      "amount" =&gt; 1599,               
                      "currency" =&gt; "usd",            
                      "description" =&gt; "This is a test payment from post data",
                      "card" =&gt; array(                
                          "number" =&gt; $data['cardNumber'],
                          "exp_month" =&gt; $data['expMonth'],
                          "exp_year" =&gt; $data['expYear']  
                      )));   
  
              } catch(Stripe_CardError $e) {  
  
                Do error checking stuff here...
  
              }catch (Exception $e) {         
                  print_r($e-&gt;getMessage());      
              } catch (ErrorException $e) {   
                  print_r($e-&gt;getMessage());      
              }
  </code></pre>
  
  <p>Like I say, this code works fine until an exception is thrown but when one is I seem unable to catch it and act upon it.</p>
  
  <p>In the Symfony debug screen shows the correct error message is returned from the api but it does not have the correct code (should be <code>402</code>):</p>
  
  <pre><code>Your card was declined.
  500 Internal Server Error - Stripe_CardError
  </code></pre>
  
  <p>I feel this is a Symfony config issue but numerous searches have not provided me with any solutions. Any ideas?</p>
  
  <p>P.s. I am also using the FOSUserBundle.</p>