What SPL exception should be used when checking the installed data before the process?

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) {
            // Which Exception do I throw? See explanation below
        }

        if($this->data1 && $this->data2) {
            // Which Exception do I throw? See explanation below
        }
    }
}

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?

, ?

.. - , - , , ..

+3
3

SPL, RuntimeException. , , (, ).

LogicException , , . LogicException , , , , ( , ).

BadMethodCallException ,

, undefined .

, , , .

( RuntimeException), RuntimeException.

+5

, , ?

, :

  • , ValidationException, Exception.
  • :
    • ValidationException_MissingData
    • ValidatonException_BadCombination


SPL, : mecanism , , , , Frameworks, .


, , . .

+3

All Articles