PHP code example of dmn / laravel-exception

1. Go to this page and download the library: Download dmn/laravel-exception library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dmn / laravel-exception example snippets




namespace App\Exceptions;

use Dmn\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
...
    /**
     * Register the exception handling callbacks for the application.
     */
    public function register(): void
    {
        parent::register();
        $this->reportable(function (Throwable $e) {
            //
        });
    }
...
}



namespace App\Exceptions;

use Dmn\Exceptions\Exception;
use Illuminate\Http\Response;

class NewCustomException extends Exception
{
    protected $code = 'sample_error_code';

    protected $message = 'Sample error message';

    protected $httpStatusCode = Response::HTTP_BAD_REQUEST;

    protected $description = 'Sample more detailed error description.';
}


{
    status_code: 400,
    code: "sample_error_code",
    message: "Sample error message.",
    description: "Sample more details error description.",
}

protected function customException(): void
{
    parent::customException();

    // your overrides here
    // example
    $this->renderable(function (\Vendor\Package\Exception $e) {
        throw new App\Exceptions\NewCustomException();
    });
}

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    // App\Exceptions\Handler::class <-- change this
    Dmn\Exceptions\Handler
);