Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't catch exceptions in laravel

I have the following situation:

  try {

        DB::beginTransaction();

        $task = new Task();
        $task->setTracker("");
        //thrown \Symfony\Component\Debug\Exception\FatalThrowableError


            DB::commit();

        }catch (\Exception $e){
            DB::rollBack();
            Log::error($e);
            //throw $e;
        }

I am not entering to the catch area.
Any idea why?

update

This is the error thrown:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Argument 1 passed to App\Models\Task::setTracker() must be an instance of Carbon\Carbon, integer given, called in /var/www/app/Services/ShareLogic.php on line 60

and will not be catched

Thanks

like image 950
SexyMF Avatar asked Apr 20 '17 08:04

SexyMF


People also ask

How do I enable errors in laravel?

Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.

How does laravel handle exception in API?

Error Handler As you can see there, we add so many exceptions inside the handleException() function. By default, the handleException() function doesn't exist, so you must modify the render() function to use the handleException(). You can add as many exceptions as you want inside this function.

Which class is used to handle exceptions in laravel?

All exceptions are handled by the App\Exceptions\Handler class. This class contains a register method where you may register custom exception reporting and rendering callbacks.

How do I disable error reporting in laravel?

You may turn off error details by setting the debug option in your app/config/app. php file to false .


1 Answers

Catching Throwable did the trick.
Have no idea why? Anyone does?

like image 53
SexyMF Avatar answered Oct 11 '22 08:10

SexyMF