PHP code example of xsga / bbphp-exception

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

    

xsga / bbphp-exception example snippets




declare(strict_types=1);

use Xsga\BBPHP\Exception\GenericException;

try {
	throw new GenericException(
		message: 'Validation failed',
		code: 422,
		params: ['field' => 'email', 'reason' => 'invalid_format']
	);
} catch (GenericException $e) {
	echo $e->getMessage(); // Validation failed
	print_r($e->getParams());
}

public function __construct(
	string $message = '',
	int $code = 0,
	protected array $params = [],
	?Throwable $previous = null
)