webman 調(diào)用函數(shù),被調(diào)用函數(shù)怎么不返回,直接返回給用戶呢
比如用fpm是直接exit 停止并輸出
webman 該怎么實現(xiàn)這個
通過throw 不同異常,再調(diào)用函數(shù)里處理,就可以避開。
簡單的:
function a(int $num){
try{
$res = test($num);
$res = test($num+1);
$res = test($num+2);
return \response($res);
}catch(\Throwable $e){
return \response($e->getMessage());
}
}
function test($num){
if($num%2){
throw new Exception('message',1112233);
}
return $num;
}
也可以封裝成一個函數(shù)
function quit($msg) {
throw new \Exception($msg);
}
就可以像exit die 那樣愉快的調(diào)用了