Symfony 5 – best practices to handle query exception

  exception, handle, php, symfony

i want to ask more experienced symfony dev about exception handling.
I know i should make and EventListener and inside handle exceptions.

But what if i got isnert into exception value should not be null?

public function onKernelException(ExceptionEvent $event)
    $exception = $event->getThrowable();
    $message = sprintf(

    $response = new Response();

    if ($exception instanceof PDOException) {
    } else {


        - { name: kernel.event_listener, event: kernel.exception }

is that right or should i do this in other way?

The second idea i got is handle this in action controller something like:

    public function addNewBonus(Request $request, RuneBonusRegisterer $registerer)
        $bonusData = json_decode($request->getContent(), true);

        $form = $this->createForm(RuneBonusType::class);

        if (!$form->isValid()) {
            return $this->json([
                'errors' => $form->getErrors(true, false)
            ], 200);


        $bonus = $form->getData();

        return $this->json(
            $bonus, 200

Source: Symfony Questions