yii2: Proper way to throw new exception(yii2:抛出新异常的正确方法)
问题描述
只是为了测试,我在我的模型中添加了这段代码,同时设置了 debug = true 和 false.
Just for testing I have added this code in my model while setting the debug = true and false.
if($packagedays < 1)
{
throw new yiiaseException( "package days cannot be less than 1" );
}
现在当 Yii 调试为真时:我得到了
Now when Yii debug is true: I am getting
异常 – yiiaseException包裹天数不能少于 1
但是当我将调试设置为 false 时我正进入(状态例外发生内部服务器错误.
But when I am setting the debug to false
I am getting
Exception
An internal server error occurred.
上述错误发生在 Web 服务器处理您的请求时.
The above error occurred while the Web server was processing your request.
我想要的是替换发生内部服务器错误.和包天数不能小于1 当debug=false
我在这里缺少什么?
谢谢.
推荐答案
你应该简单地抛出一个 UserException :
You should simply throw a UserException :
UserException 是旨在向最终用户显示的异常的基类.
UserException is the base class for exceptions that are meant to be shown to end users.
阅读更多:http://www.yiiframework.com/doc-2.0/yii-base-userexception.html
这篇关于yii2:抛出新异常的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:yii2:抛出新异常的正确方法
基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
