- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我应该什么时候使用 InvalidArgumentException什么时候UnexpectedValueException ?它们在我看来是一样的。
Note一个扩展了 LogicException,另一个扩展了 RuntimeException,因此在我看来,差异应该不会那么微妙。
最佳答案
仔细查看手册页上的描述:
Exception thrown if an argument is not of the expected type.
(描述为如果参数与预期值不匹配则抛出异常。
until mid-2014,但已更改when PHP 5.6 got introduced)
Exception thrown if a value does not match with a set of values. Typically this happens when a function calls another function and expects the return value to be of a certain type or value[,] not including arithmetic or buffer related errors.
由此,我们可以得出结论,InvalidArgumentException
旨在检查传递给函数的参数类型,而 UnexpectedValueException
旨在< em>验证值与有效值集,可能在函数的内部计算期间(例如,从其他函数返回的值)。
请注意,检查参数的值是一种灰色区域;可以说,由于 InvalidArgumentException 扩展了 LogicException
,它应该只处理 should lead directly to a fix in your code.
的情况。由于在输入值超出范围的情况下引发异常可能是完全预期的 runtime 行为,因此这会留下 UnexpectedValueException
(扩展 RuntimeException
) 作为这种情况下的唯一候选人。
关于php - InvalidArgumentException 与 UnexpectedValueException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12483667/
我应该什么时候使用 InvalidArgumentException什么时候UnexpectedValueException ?它们在我看来是一样的。 Note一个扩展了 LogicException
我想创建一个新的 Symfony 项目,但它给了我一个 UnexpectedValueException。 我是否使用:symfony new my_project_name --full或者comp
我正在使用 Laravel 5.1,但出于某种原因,我时常遇到此错误: UnexpectedValueException in Response.php line 397: The Response
我是 laravel 的新手,我正在尝试安装 laravelcollective。我只是关注文档 here我在我的项目目录中使用它: composer require "laravelcollecti
什么时候应该使用 Exception、InvalidArgumentException 或 UnexpectedValueException? 我不知道它们之间的真正区别,因为我一直使用 Except
在 AWS 服务器上,我有一个测试环境并且运行良好,但是在我尝试部署新更改时突然出现以下错误(顺便说一句,与此同时,由于 HomeOffice,WIFI 发生了变化) Unzip with unzip
我正在尝试在目录 foo/bar 中使用 Composer 开发一个 PHP 库(称为 /work/a)与 composer.json内容: { "name": "foo/bar",
我正在尝试在目录 foo/bar 中使用 Composer 开发一个 PHP 库(称为 /work/a)与 composer.json内容: { "name": "foo/bar",
为什么UnexpectedValueException会在session_start()中抛出? 我的对象具有 SPLObjectstorage 的属性。该对象被分配给 session ,如 $_SE
以下代码: $zip = new ZipArchive(); if ($zip->open('./archive.zip', ZIPARCHIVE::CREATE) !== TRUE) { d
我想在我的项目中为纬度和经度添加一个 POINT 字段,我发现了这个 tutorial我模仿以确保它正常工作,但我仍然坚持为什么现在会发生此错误: UnexpectedValueException i
我才刚刚开始使用 Apache Solr,我也不是 PHP 高手。 Apache Solr 正在运行并在浏览器中粘贴此查询显示一个 XML 文档: http://localhost:8983/solr
我正在尝试使用 composer 安装一个 github 项目并得到以下错误 Composer [UnexpectedValueException]您的 github.com 的 Github oau
我正在尝试使用 composer 安装 github 项目并收到以下错误 Composer [UnexpectedValueException] 您用于 github.com 的 Github oau
Composer 给出以下错误: Could not load package phpspec/prophecy in http://packagist.org: [UnexpectedValueEx
为什么我会收到此错误。我创建了一个 PortfolioController。然后我用这个做了一条路线 Route::get('portfolio','PortfolioController'); 所
我是socketIO和elephantIO的新手,我正在尝试从php文件emit_test.php发送到 Node 服务器,如下所示 ini_set("display_errors",5); incl
我是一名优秀的程序员,十分优秀!