草庐IT

try-catch-else

全部标签

php - catch 不工作

我很困惑。是什么导致“catch”无法正常工作?我该如何解决?getMessage());}?>实际输出[27-Apr-201009:43:24]PHPFatalerror:Uncaughtexception'Exception'withmessage'BOOM'in/mycode/exception_problem/index.php:4Stacktrace:#0{main}thrownin/mycode/exception_problem/index.phponline4期望的输出shouldhappen:BOOMPHP版本5.2.3在php_info()中,我没有看到任何可以禁用

php - return true 不返回或我的 else 声明不起作用?

由于某种原因,我的else语句没有触发,我认为我的方法由于某种原因没有返回true。主要代码functionmsg($content){//functionthatechosoutpagewithcontentinit}$car=newyamiko_car;if(!$car->add())//returnsboolfalseonfailandtrueonsuccess{msg($car->error);}else{msg('Carhasbeenadded');}并且方法不是它确实在我测试数据但只是在那里发表评论的地方失败时返回false。已经对其进行了全部测试,并且运行良好。publi

php - Symfony2 : error trying to send an email with Swiftmailer

当我尝试使用swift发送电子邮件时遇到以下问题Symfony2项目:刷新电子邮件队列时发生异常:预期响应代码220但得到代码“”,消息为“。我在localhost中,我尝试使用我的主机OVH的邮件。这是我的config.yml:#SwiftmailerConfigurationswiftmailer:transport:"%mailer_transport%"auth_mode:"%mailer_auth_mode%"host:"%mailer_host%"port:"%mailer_port%"username:"%mailer_user%"password:"%mailer_pa

php - 如何处理其他 try catch block 中的异常?

我的例子:classCustomExceptionextends\Exception{}classFirstClass{functionmethod(){try{$get=external();if(!isset($get['ok'])){thrownewCustomException;}return$get;}catch(Exception$ex){echo'ERROR1';die();}}}classSecondClass{functionget(){try{$firstClass=newFirstClass();$get=$firstClass->method();}catch(

用于测试 catch block 的 PHPunit

我有这样一个代码:publicfunctionone(){try{$this->two();}catch(Exception$E){$this->three();}}我如何测试调用了$this->three()函数?我尝试“按代码模拟”$this->two()并抛出错误而不是它的原始代码,但最终错误被phpunit本身捕获。尝试了setExpectedException,但它也没有解决问题-catch再次在phpunit中运行,只是被忽略了。函数$this->three()在这两种情况下都没有被调用。谢谢! 最佳答案 问题是所描述的

PHP 7 try catch : unable to catch "Catchable fatal error"

我正在玩try-catchblock:loadHTMLFile($str);$domOb->preserveWhiteSpace=false;$container=$domOb->getElementById('ormaininfotab');echo$container;//getMessage().".File:".$e->getFile().",line:".$e->getLine();}catch(Error$e){echo"Error".$e->getMessage().".File:".$e->getFile().",line:".$e->getLine();}?>我的结果

php - 高级自定义字段 - 带有 true/false 复选框的 If/Else 语句

我使用Wordpress的高级自定义字段添加了一个真/假复选框。我希望能够选择修改页面模板的选项。我正在将此选项添加到WooCommerce/Wordpress中的产品类别。我在代码中包含了这段逻辑。我有以下代码,但它不起作用。我怀疑是因为它不在循环内。但是我要插入的代码包括循环。非常感谢对代码的任何想法/指导EmptyTest} 最佳答案 好的,我重新阅读了ACF的文档并发现了以下内容(http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-fr

php - fatal error : Out of memory (allocated 1979711488) (tried to allocate 131072 bytes) error occur while writing xlsx file using phpexcel

我已经集成了xlsx文件,用于使用phpexcel从数据库写入。我想在xlsx文件中写入3,00,000条记录。但直到通过Fatalerror:Outofmemory(allocated1979711488)(triedtoallocate131072bytes)我的PHP版本5.3.28我还设置了phpini和单元格缓存,请参阅下面的代码ini_set('max_execution_time',-1);ini_set('memory_limit','-1');$cacheMethod=PHPExcel_CachedObjectStorageFactory::cache_in_memo

php - 试图避免 "spaghetti code",为什么多个 if-else 不好?

我刚刚在读top100signsofspaghetticode我遇到了数字4,它简单地说明:if($status=="awake"){$actitivity="Writingspaghetticode";}elseif($healthstatus=="OK"){$activity="Sleep";}else{print"CALL911IMMEDIATELY!";}我在otherspaghettidiscussions中看到过这种多重if-else模式.我有点困惑为什么会这样,即使它适用于这个例子。上面的例子不好是因为第一个变量是activity,它表示编码器需要一些sleep,所以这是

php - fatal error : uncaught exception without try/catch block

我试图在表单字段为空以及插入查询不成功时抛出异常。我见过有人在没有使用try/catchblock并且没有包含Exceptions类的情况下抛出异常。有谁知道我会怎么做?这是我在没有填写所有字段时遇到的错误:fatalerror:在第94行的/vagrant/web/Assignment4/Person.php中出现未捕获的异常“异常”,消息为“错误:以下字段为空-标题、电话号码、电子邮件”异常:错误:以下内容字段为空-标题、电话号码、电子邮件,位于第94行的/vagrant/web/Assignment4/Person.php调用堆栈:0.00146381681.{main}()/v