手动抛出错误
try{
$num1 = 3;
if ($num1 == 3) {
throw new \Exception("自定义错误");
}
}catch(\Exception $exception){
info($exception->getMessage());
}
日志打印出了: 自定义错误
Laravel 异常错误信息处理
use Illuminate\Http\Exceptions\HttpResponseException;
/**
* Laravel 异常错误信息处理
* @author wgchen
* @date 2022-2-14
*/
public function checkCrmLegal()
{
throw (new HttpResponseException(response()->json([
'status_code' => 422,
'message' => 'asdf',
], 200)));
}
use Symfony\Component\HttpKernel\Exception\HttpException;
throw new HttpException(400, 'asdf');