PHP SPL Exceptions Use Cases
An exception is used to immediately terminate the operation due to incorrect use of the code or incorrect data transferred for processing, or the inability to transfer data to another system. LogicException (and inherited) is thrown before the operation is executed, due to incorrect code usage. For example, an unknown function is called, a variable is passed with the wrong type, value, or wrong string length. RuntimeException (and inherited) is thrown during the execution of an operation, due to invalid data being passed or the inability to pass data to another system. For example, while processing the configuration file, it turned out that the value of the parameter was incorrect or the connection to the database was not established. Throwing LogicException and RuntimeException results in a HTTP 500 (Internal Server Error) server response because the error is on the server side. SPL Exceptions Class Tree LogicException BadFunctionCallException ...