pet.php:
<?php
namespace App;
use App\PetException as PetException;
use App\MinEnergyException as MinEnergyException;
use App\MaxEnergyException as MaxEnergyException;
final class Pet
{
private function checkEnergy()
{
if ($this->energy <= $this->min) {
throw new MinEnergyException;
}
if ($this->energy > $this->max) {
throw new MaxEnergyException;
}
}
}
pet_exception.php:
<?php
namespace App;
class PetException extends \Exception
{
}
class MinEnergyException extends PetException
{
protected $message = 'MinEnergyError: the minimum energy must be at least 1!';
}
class MaxEnergyException extends PetException
{
protected $message = 'MaxEnergyError: the maximum energy should not be more than 100!';
}
index.php:
<?php
use App\Pet as Pet;
use App\PetException as PetException;
require_once 'vendor/autoload.php';
try {
$toby = new Pet('toby', 8, 0);
} catch (PetException $e) {
echo $e->getMessage();
}
Ошибка:
Fatal error: Uncaught Error: Class "App\MinEnergyException" not found in C:\My\Soft\OpenServer\domains\new.loc\MyProjects\pet-bot\app\classes\pet.php:88 Stack trace: #0 C:\My\Soft\OpenServer\domains\new.loc\MyProjects\pet-bot\app\classes\pet.php(20): App\Pet->checkEnergy() #1 C:\My\Soft\OpenServer\domains\new.loc\MyProjects\pet-bot\index.php(11): App\Pet->__construct() #2 {main} thrown in C:\My\Soft\OpenServer\domains\new.loc\MyProjects\pet-bot\app\classes\pet.php on line 88
Это часть кода, где задействовано исключение.