PHP code example of php-enspired / exceptable
1. Go to this page and download the library: Download php-enspired/exceptable 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/ */
php-enspired / exceptable example snippets
use at\exceptable\ {
Fault,
EnumeratesFaults
};
// A simple Fault, just for you
enum ProcessFault : string implements Fault {
use EnumeratesFaults;
case NotReady = "{type} is not ready (status is '{status}')";
}
class Example {
public function __construct( public ExampleStatus $status ) {}
}
enum ExampleStatus {
case Preparing;
case Ready;
}
$example = new Example(ExampleStatus::Preparing);
if ($example->status !== ExampleStatus::Ready) {
throw (ProcessFault::NotReady)([
"type" => $example::class,
"status" => $example->status
]);
}
// results in:
// Fatal error: Uncaught at\exceptable\Spl\RuntimeException: ProcessError.NotReady: Example is not ready (status is 'preparing')