PHP code example of wernerdweight / enhanced-exception

1. Go to this page and download the library: Download wernerdweight/enhanced-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/ */

    

wernerdweight / enhanced-exception example snippets


use WernerDweight\EnhancedException\Exception\AbstractEnhancedException;

class MyException extends AbstractEnhancedException
{
    /** @var int */
    public const EXCEPTION_SOMETHING_BAG_HAPPENED = 1;
    /** @var int */
    public const EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION = 2;

    /** @var string[] */
    protected static $messages = [
        self::EXCEPTION_SOMETHING_BAG_HAPPENED => 'Something bad happened! Helpful, I know.',
        self::EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION => 'Didn\'t expect Spanish inquisition to reach user %s!',
    ];
}

throw new MyException(MyException::EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION, [$user->getUsername()]);
// will throw `Didn't expect Spanish inquisition to reach user Ferdinand II!`