0

I am trying to upload a file. And if it throws an exception I don't want to see the "whoops" page. Instead it will go back the previous page with a message. This is what I tried,

try {
    $data = Excel::toArray(new Import, request('file'));
} catch (\Exception $e) {
    return back()->withErrors("an exception occured");
}

But it still gives me the whoops page whenever any exception occurs.

How to solve it?

Nabil Farhan
  • 1,444
  • 3
  • 25
  • 41
  • 1
    Add said exception to your question. Exceptions reference backtrace with lines of code that caused it, so make sure you also add the code mentioned in the exception to your question. – d3jn Oct 25 '19 at 06:52

2 Answers2

0

I don't believe you will be able to catch/handle a Fatal Error. The script has stopped and is unrecoverable at this point. A shutdown handler is running as the script is shutting down. This is being handled by a shutdown function via register_shutdown_function.

Illuminate\Foundation\Bootstrap\HandleExceptions@handleShutdown will check to see if there was an error and if it was fatal and then pass a Symfony\Component\Debug\Exception\FatalErrorException to its own handler as an example.

lagbox
  • 48,571
  • 8
  • 72
  • 83
  • No. The problem is still there. – Nabil Farhan Oct 25 '19 at 06:26
  • If it helps, I am specially trying for "Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Allowed memory size of 62914560 bytes exhausted (tried to allocate 14680064 bytes)" exception – Nabil Farhan Oct 25 '19 at 06:27
0

Laravel 5.0 and up ships with an error handler at app/Exceptions/Handler.php. Here you can define a handler for any exception in your application. This way you don't need to add extra error handling in your controllers.

All information can be found in the documentation: https://laravel.com/docs/6.x/errors#the-exception-handler

Jerodev
  • 32,252
  • 11
  • 87
  • 108