Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception - Laravel on PHP 7

Practice




Uncaught TypeError: Argument 1 passed to AppExceptionsHandler::report() must be an instance of Exception, instance of TypeError given, called in
or an error like this
Uncaught TypeError: Argument 1 passed to App\\Exceptions\\Handler::report() must be an instance of Exception, instance of Error given, called

after upgrading to PHP7, Laravel started throwing this error
the error is in the exception handling — how do I fix it?
without thinking too long, and after trying various methods and tips, I decided to change the framework core, in the file
/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
add
+use Exception;
+use Symfony\Component\Debug\Exception\FatalThrowableError;



in the handleException method of the HandleExceptions class, add this condition

public function handleException($e)
{
+ if (! $e instanceof Exception) {
+ $e = new FatalThrowableError($e);
+ }
+
$this->getExceptionHandler()->report($e);

if ($this->app->runningInConsole())

.....

second option, to do it differently in the same file and the same function

public function handleException($e)
{
if (! $e instanceof Exception) {
$e = new \Exception($e->getMessage()."\n".$e->getTraceAsString(), $e->getCode()); // new FatalThrowableError($e);
}...

this should help

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Famworks"

Terms: Famworks