最近搬到了php7。发生以下错误:
argument 1 passed to MyClass\Throwable::exceptionHandler() must be an instance of Exception, instance of Error given
各自的班级
namespace MyClass;
class Throwable
{
public function exceptionHandler(\Exception $exception)
{
//logic here
}
}
如docs
中所述现在通过抛出错误例外来报告大多数错误。
这是否意味着我必须向异常处理程序提供Error
或更一般Throwable
的实例?
答案 0 :(得分:7)
Errors
和Exceptions
都延伸Throwable
但是错误不会从Exception
延长。
因此,您的ExceptionHandler必须接受Throwable
类型的对象才能接受Errors
。
这是最简单的解决方法,但您可能希望重命名$ exception以使其清晰。
namespace MyClass;
class Throwable
{
public function exceptionHandler(\Throwable $exception)
{
//logic here
}
}
注意:新的Error
类不应与ErrorException
混淆,Exception
经常被用作将PHP 5错误转换为具有语义含义的/home/a/torch/install/bin/luajit: /home/a/torch/install/share/lua/5.1/nn/THNN.lua:699: Assertion `cur_target >= 0 && cur_target < n_classes' failed. at /tmp/luarocks_nn-scm-1-6937/nn/lib/THNN/generic/ClassNLLCriterion.c:31
stack traceback:
[C]: in function 'v'
/home/a/torch/install/share/lua/5.1/nn/THNN.lua:699: in function 'ClassNLLCriterion_updateOutput'
...e/a/torch/install/share/lua/5.1/nn/ClassNLLCriterion.lua:41: in function 'updateOutput'
...torch/install/share/lua/5.1/nn/CrossEntropyCriterion.lua:13: in function 'forward'
.../a/torch/install/share/lua/5.1/nn/StochasticGradient.lua:35: in function 'train'
a.lua:34: in main chunk
[C]: in function 'dofile'
/home/a/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x00406670
对象的设备。