I'm struggling to figure out when to use a couple of PHP SPL Exceptions , specifically in the scenario below,
class MyClass {
protected $data1;
protected $data2;
public function setData1($data1) {
$this->data1 = $data1;
}
public function setData2($data2) {
$this->data2 = $data2;
}
public function invokeProcess() {
$this->validateData();
}
protected function validateData() {
if(!$this->data1) {
}
if($this->data1 && $this->data2) {
}
}
}
I have a class that is built. Then the user sets some data about the object and calls the process. The first thing this process does is check the data on the object to make sure that the required data is present, the data combinations are correct, etc., and if not, an exception must be thrown.
So what are the exceptions I am throwing?
My check checks for two scenarios,
- Missing data, aka data that has not been installed.
- Bad data combination.
# 1 BadMethodCallException, RuntimeException LogicException. # 2 , LogicException?
, ?
.. - , - , , ..