PHP 可执行文件抛出异常不起作用


PHP exec throw exception not working

我有一个脚本"test.php",它使用命令可执行文件在PHP CLI中运行。在此文件中,我将异常用于某些特殊情况,以便在 CLI 之外捕获它们并停止执行。不幸的是,没有抛出异常,我不知道为什么。我无法使用exit()命令,所以我需要知道以下脚本有什么问题

index.php
$cliObj = new CliClass('test.php');
$cliObj->run();
$cliObj->setOutputFile('../test.txt');
test.php
if ($x == 0) throw new 'Exception("TEST");

我知道变量$x是 0,但没有抛出 i 异常。

10倍!

代码应该是这样的:

if ($x == 0) {
  throw new 'Exception("TEST");
}