Skip to content

Docs ‐ Exception Handler

Isaac Sai edited this page Jan 21, 2024 · 3 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 Sparors\Ussd\Contracts\ExceptionHandler;

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