您当前的位置: 首页 >  知其黑、受其白 ar

Laravel 异常错误信息处理

知其黑、受其白 发布时间:2021-02-04 18:35:41 ,浏览量:6

手动抛出错误

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');

关注
打赏
查看更多评论

知其黑、受其白

暂无认证

  • 6浏览

    0关注

    1066博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录