PHP code example of adlacruzes / php-base-exception

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

    

adlacruzes / php-base-exception example snippets


use Adlacruzes\Exceptions\BaseException;

class SomethingNotFoundException extends BaseException {}

try {
    throw new SomethingNotFoundException();
} catch (SomethingNotFoundException $e) {
    echo $e->getMessage();
}

echo $e->getMessage();
// Something not found

class SomethingNotFoundException extends BaseException {

    /**
     * @var mixed
     */
    protected $message = 'This is a default message';
    
}

try {
    throw new SomethingNotFoundException();
} catch (SomethingNotFoundException $e) {
    echo $e->getMessage();
}

echo $e->getMessage();
// This is a default message

try {
    throw new SomethingNotFoundException('information');
} catch (SomethingNotFoundException $e) {
    echo $e->getMessage();
}

echo $e->getMessage();
// Something not found: information