Exception handling of spool framework

Time:2021-3-2

Using “set” in the spool framework_ error_ Handler and set_ exception_ Handler doesn’t work at all. The reason is that it is hijacked from the bottom by the spool extension. When you need to catch the running errors and exceptions as a whole, you can only try.. catch the function bound to onrequest

In addition, in php7, both error and exception implement throwable interface, so how to catch these two kinds of errors at the same time should catch throwable

 

1 try {
 2             $this->kernal->process($this->request, $this->response);
 3 } catch (\Throwable $throwable) {
 4 // get header
 5             $accept = $this->request->header["accept"];
 6 
 7             if (strpos($accept, "json")) {
 8                 $data["file"] = $throwable->getFile();
 9                 $data["codeLine"] = $throwable->getLine();
10                 $data["error"] = $throwable->getMessage();
11                 $this->response->setHeader("Content-Type", "application/json");
12                 $this->response->send(json_encode($data));
13             } else {
14                 $str = <<Error Message: {$throwable->getMessage()}       
16 Error File: {$throwable->getFile()}    
17 Error Line: {$throwable->getLine()}
18 Error Traces:
19 EOL;
20                 foreach ($throwable->getTrace() as $trace){
21                     $str .= "{$trace["file"]}:{$trace["line"]}";
22                 }
23                 $this->response->send($str);
24             }
25 
26 }

 

In case of interface access error, it will be displayed in JSON format

The page is displayed as a web when it is accessed (please ignore this ugly style)