Home > Article > Backend Development > Briefly describe the example of catching exception interrupt in PHP
Summary: When an abnormal situation occurs in the PHP program, such as a fatal error, timeout, or unknown logical error that causes the program to interrupt, register_shutdown_function can be used at this time. Exception handling.
When an abnormal situation occurs in the PHP program, such as a fatal error, timeout, or unknown logical error that causes the program to be interrupted, register_shutdown_function can be used for exception handling.
#For example, to determine whether a script has been executed, you can set an attribute to false, set it to true when the execution is completed, and finally use the method specified by the register_shutdown_function function to determine , and do further exception handling, as shown in the code:
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class IndexController extends Controller { /** * Whether the script execution is completed * @var bool */ protected $complete = false ;
public function __construct() { register_shutdown_function([$this, 'shutdown']); }
/** * Exception handling */ public function shutdown() { if ($this->complete === false) { dump('www.tanteng.me'); //Logs should be output and exception handling operations should be performed here Logs should be output and exception handling operations should be carried out. ##} }
|
The above is the detailed content of Briefly describe the example of catching exception interrupt in PHP. For more information, please follow other related articles on the PHP Chinese website!