Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bradders's avatar

Catching Cashier Errors

I'm setting up Laravel Cashier in my app to accept payment through Stripe. I've got it working, and had starting trying to deal with errors/edge cases, and I'm having trouble catching errors when I try $user->newSubscription()

I've trying to catch a variety of cases: Laravel\Cashier\Exceptions\PaymentFailure, Stripe\Exception\InvalidRequestException but even when I wrap my code in a try/catch it errors out.

// Controller
try {
    $subscription = $user->newSubscription("name", "plan")->create($payment_method);
} catch (Exception $e) {
    return response()->json(["error" => ["code" => 500, "message" => "WTF"]], 500);
}

My frontend makes an ajax request to this controller but never returns the object from my catch. I've tried to following, too:

catch( \Stripe\Exception\InvalidRequestException $e ) catch(Laravel\Cashier\Exceptions\PaymentFailure $e)

But none seem to work. Hopefully this is a dumb question and I'm missing something obvious! :)

0 likes
2 replies
alexandersix's avatar

This may be a ridiculous answer, but it’s come back to bite me a few times—did you import your Exception class in this file? If not, you may be trying to catch an Exception that Laravel doesn’t know about at this point in the code.

If you haven’t imported it, I think the quick fix would be to change Exception to \Exception!

Let me know if that does the trick, or if I’m completely off-base!

bradders's avatar

HI @alexandersix thanks for the reply! I did try that, to no avail! I also tried importing the aformentioned error classes too and trying to catch the shorter name, catch(PaymentFailure $e) etc, but that didn't help either!

Please or to participate in this conversation.