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:抛出新异常的正确方法
				
        
 
            
        基础教程推荐
- php中的PDF导出 2022-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				