E
E
Evgeny Musonov2020-02-02 10:24:00
Laravel
Evgeny Musonov, 2020-02-02 10:24:00

Why doesn't the exception work?

Exception

namespace App\Exceptions;

use Exception;
use Illuminate\Support\Facades\Log;

class ResizeDirNotFoundException extends Exception
{
    public function report(Exception $exception)
    {
        Log::error('Resize dir is empty');
        parent::report($exception);
    }
}

calling
private function validateResizeParams($params)
    {
        if (empty($params['dirForSave'])) {
            throw new ResizeDirNotFoundException('Resize dir is empty');
        }
    }

processing
public function resize($width, $height, $dirForSave, $quality = 100)
    {
        $params = [
            'width'      => $width,
            'height'     => $height,
            'dirForSave' => $dirForSave
        ];

        try {
            if (!is_null($this->file) && $this->validateResizeParams($params)) {
                //resize
            }
        } catch (Exception $exception) {
            return redirect('/');
        }
    }

The log is not created, the exception is not processed, the form is successfully processed, tell me, please, where is the cant?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Musonov, 2020-02-08
@evmusonov

The exception itself works, but you need to remove the report method, because the class Extensiondoes not contain it. To
make the redirect work, you need to replace with
return redirect('/');
redirect('/')->send();

A
Alex Wells, 2020-02-02
@Alex_Wells

What should have happened? You catch eksepsheny. } catch (Exception $exception) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question