Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Simple Exception Laravel Package

holicz/simple-exception

Lightweight base exception for PHP/Laravel with structured context: a safe public message for users, a private debug message for logs, and an HTTP status code. Create your own exceptions by extending BaseException and pass an ExceptionContext.

View on GitHub
Deep Wiki
Context7

About

Simple base exception class providing public and private context inspired by https://github.com/EasyCorp/EasyAdminBundle

Installation and usage

Installation with composer

composer require holicz/simple-exception

Your exception class:

<?php

namespace App\Exception;

use holicz\SimpleException\BaseException;
use holicz\SimpleException\ExceptionContext;

class CouldNotRemoveArticleException extends BaseException
{
    public function __construct(int $id)
    {
        $exceptionContext = new ExceptionContext(
            'There was an error during article removal. Please try again later.',
            sprintf('Could not delete article with id %d', $id),
            500 // HTTP status code
        );
    
        parent::__construct($exceptionContext);
    }
}

Your code

try {
    ...
} catch (MyException $e) {
    // Available methods
    $e->getPublicMessage(); // Show to user
    $e->getDebugMessage(); // Log
    $e->getStatusCode();
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours