【TP5 :错误和调试】抛出异常

版权声明:本文为ywcmoon原创文章,未经允许不得转载。 https://blog.csdn.net/qq_39251267/article/details/82496862

抛出异常

手动抛出异常

使用 \think\Exception 类抛出异常

// 使用think自带异常类抛出异常
throw new \think\Exception('异常消息', 100006);

自定义异常类抛出异常

throw new \foobar\Exception('异常消息');

助手函数抛出异常:

exception('异常消息', 100006);

// 使用自定义异常类
exception('异常消息', 100006, \foobar\Exceeption);

抛出 HTTP 异常

使用\think\exception\HttpException类抛出异常

// 抛出 HTTP 异常
throw new \think\exception\HttpException(404, '异常消息', null, [参数]);

助手函数abort抛出异常:

abort(404, '异常消息', [参数])

HTTP异常可以单独定义异常模板,具体参考后面章节404页面

猜你喜欢

转载自blog.csdn.net/qq_39251267/article/details/82496862