0

Using Laravel 5.7 on PHP 7.3. I've spent hours on this and read every single answer on Stack Overflow, but nothing wants to work. I'm forcing an exception to happen in my code:

public function my_function(Request $request) {
    try {
        require_once(app_path() . '/Libs/my-custom-inexisting-php-file.php');
    } catch (\Exception $e) {
        // Do something
    }
}

I'm still getting the Laravel exception, it's not getting within the catch statement.

Symfony\Component\Debug\Exception\FatalErrorException: App\Http\Controllers\MyController::my_function(): Failed opening required '/home/vagrant/code/my-project/app/Libs/my-custom-inexisting-php-file.php'

I tried with Exception, \Exception, Throwable, \Throwable, ErrorException, \ErrorException, Symfony\Component\Debug\Exception\FatalErrorException, \Error, Error.

And I'm still not catching it. Any help would be very much appreciated.

user11657407
  • 312
  • 2
  • 12
Kunstmann
  • 109
  • 1
  • 10
  • 2
    Or this one [Try Catch cannot work with require_once in PHP?](https://stackoverflow.com/questions/5369488/try-catch-cannot-work-with-require-once-in-php) - if your goal is to test catching exceptions you've picked a bad test. Just `throw Exception('Blah');` instead of invoking an uncatchable scenario :) – AD7six Jan 17 '20 at 09:11
  • Brilliant! I'm so stupid, never thought it could be related to the statement itself. Thank you guys. – Kunstmann Jan 17 '20 at 09:27

0 Answers0