Skip to content

Docs ‐ Exception Handler

papamarfo edited this page Jul 30, 2026 · 4 revisions

Introduction to Exception Handling

Bugs can appear in software, causing them to crush. Laravel USSD allows us to handle any exception that may arrive in running of our application and return the error we want to show the users.

Creating Exception Handler

php artisan ussd:exception-handler CatchExceptionHandler

Implement how exception should be handled.

<?php

namespace App\Ussd;

use Exception;
use Speso\Ussd\Contracts\ExceptionHandler;

class CatchExceptionHandler implements ExceptionHandler
{
    public function handle(Exception $exception): string
    {
        return 'Sorry, something when wrong: '.$exception->getMessage();
    }
}

Clone this wiki locally