PHP code example of try / predict-exception

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

    

try / predict-exception example snippets



TryPhp\PredictExeptionTrait;

$assertions = new class() {
	use PredictExeptionTrait();
} 

$assertions->predictException(function () {
	throw new \RuntimeException('Oooops. Something broke.')
}, \RuntimeException::class); // won't throw an exception

$assertions->predictException(function () {
}, \Exception::class); // will throw an exception

$assertions->predictException(function () {
	throw new \RuntimeException('something else happened.');
}, \Exception::class); // will throw an exception