Catching Stripe errors with Try/Catch PHP method

If you’re using the Stripe PHP libraries and they have been namespaced (such as when they’re installed via Composer) you can catch all Stripe exceptions with:

<?php 
try {
  // Use a Stripe PHP library method that may throw an exception....
  \Stripe\Customer::create($args);
} catch (\Stripe\Error\Base $e) {
  // Code to do something with the $e exception object when an error occurs
  echo($e->getMessage());
} catch (Exception $e) {
  // Catch any other non-Stripe exceptions
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)