1. Go to this page and download the library: Download sandromiguel/php-throw 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/ */
sandromiguel / php-throw example snippets
try {
$value = -5;
if ($value < 0) {
throw new InvalidArgumentException('The value must be greater than or equal to 0.');
}
// ...
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
}
try {
ThrowInvalidArgumentException::ifZeroOrNegative(-1);
} catch (\PhpThrow\ThrowInvalidArgumentException $e) {
echo $e->getMessage(); // Output: The value must be greater than or equal to 0.
}
try {
ThrowInvalidArgumentException::ifZeroOrNegativeWithValue(-1);
} catch (\PhpThrow\ThrowInvalidArgumentException $e) {
echo $e->getMessage(); // Output: The value -1 must be greater than or equal to 0.
}
ThrowInvalidArgumentException::ifZeroOrNegativeWithValue(
-1,
'Value must be positive'
); // Output: Value must be positive. Provided -1
use PhpThrow\ThrowPageNotFoundException;
$page = 'non-existent-page';
ThrowPageNotFoundException::forPage($page); // Throws an exception with the message "The page 'non-existent-page' was not found."
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.