PHP code example of tomphp / exception-constructor-tools
1. Go to this page and download the library: Download tomphp/exception-constructor-tools 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/ */
tomphp / exception-constructor-tools example snippets
use TomPHP\ExceptionConstructorTools\ExceptionConstructorTools;
class MyExceptionClass extends \RuntimeException
{
use ExceptionConstructorTools;
public static function forEntity($entity)
{
return self::create(
'There was an error with an entity of type %s with value of %s.',
[
self::typeToString($entity)
self::valueToString($entity)
]
);
}
}
if ($errorOccurred) {
throw MyExceptionClass::forEntity($entity);
}