Use throw keywords
After establishing an Exception object, you can return objects, but should not be used like this, better ways to replace it with the THROW keyword. Throw is used to throw an exception:
Throw New Exception ("My Message", 44);
Throw will abort the script and make the relevant Exception objects available to the customer code.
The following is an improved getcommandObject () method:
Index_php5.php
php // php 5 Require_once ('cmd_php5 / command.php'); class commandManager {private $ cmddir = "cmd_php5"; function getcommandObject ($ cmd) {$ PATH = "{$ this-> cmddir} / {$ CMD} .php "; if (! file_exists ($ PATH)) {throw new exception;} Require_once $ path; if (! Class_exists ($ cmd)) {throw new Exception (" Class $ CMD Does Not Exist ");} $ CMD); if (! $ class-> issubclassof (New Reflection")) {throw new exception ("$ cmd is not a commnd") } RETURN NEW $ cmd ();}}?>
In the code, we used the reflection API to determine if the given class belongs to the Command type. Executing this script under the wrong path will report this error:
Fatal error: Uncaught exception 'Exception' with message 'Can not find command / xrealcommand.php' in /home/xyz/BasicException.php:10 Stack trace: # 0 /home/xyz/BasicException.php(26): CommandManager-> GetcommandObject ('XRealcommand') # 1 {main} thrown in /Home/xyz/basicexception.php on line 10
By default, throw an exception causes one
Fatal Error
. This means that there is a security mechanism with an abnormal class. And only one error mark cannot have such a function. Processing error tag failed to continue using the error value of your script.