Symfony 2.1 + try / catch 块在控制台命令中不起作用



我正在使用一个通过cron执行的控制台命令。我想捕获每个异常并将其写入日志,但我的捕获根本不起作用。

抛出错误的部分代码是在调用"ejecutar"(这是故意的)时,错误被打印到控制台,但catch之后的代码不打印任何东西在日志

<?php
namespace dacicontratosBundleCommand;
use SymfonyBundleFrameworkBundleCommandContainerAwareCommand;
use SymfonyComponentConsoleEventConsoleExceptionEvent;
use SymfonyComponentConsoleInputInputArgument;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
//logger
use PsrLogLoggerInterface;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentTemplatingEngineInterface;
class SeguimientosRemainderEmailCommand extends ContainerAwareCommand
{
    //Administrador
    protected $emailAdmin       = "....@.....sv";
    protected $clasePhp         = "SeguimientosRemainderEmailCommand.php";
    protected $nombreProceso    = "SeguimientosRemainderEmail";
    protected $comando          = "dacicontratosBundle:seguimientos_remainder_email";
    protected $descripcion      = "Recordatorio semanal para seguimiento de contratos";
    protected $tiempoEjecucion  = "Lun | 8:00am";
    protected $mensaje          = "";
    protected $asunto           = "ITIGES - Servicio de Notificaciones - ";
    protected $logger;
    protected $text         = "";
    protected function configure()
    {
        $this->setName($this->comando)
             ->setDescription($this->descripcion)
             ->addArgument('my_argument', InputArgument::OPTIONAL, 'Argument description');
    }
    protected function execute(InputInterface $input, OutputInterface $output)
    {

        try{
            //logger
            $this->logger = $this->getContainer()->get('logger');
            $this->text = strtoupper('---- INICIO SEGUIMIENTOS REMAINDER EMAIL -----');
            $this->logger->info($this->text);
            $this->getContainer()->enterScope('request');
            $this->getContainer()->set('request', new SymfonyComponentHttpFoundationRequest(), 'request');
            ejecutar(); //HERE IS WHERE IT FAILS

            $this->mensaje = "<strong>Éxito</strong>" ."<br/>";
            $this->mensaje = $this->mensaje . "<strong>Clase php:</strong>              ".$this->clasePhp."<br/>";
            $this->mensaje = $this->mensaje . "<strong>Comando ejecutado:</strong>      ".$this->comando."<br/>";
            $this->mensaje = $this->mensaje . "<strong>Descripción:</strong>            ".$this->descripcion."<br/>";
            $this->mensaje = $this->mensaje . "<strong>Ejecución programada:</strong>   ".$this->tiempoEjecucion."<br/>";
            $datetime = new DateTime();
            $this->mensaje = $this->mensaje . "<strong>Hora de ejecución:</strong>      ".$datetime->format('Y-m-d h:i:s');
            $this->enviarMailAdmin($this->comando, $this->mensaje);

        }catch (Exception $re) {
            $this->logger->error($re->getMessage());
        }
    }

这是我试图捕获的错误但是我想捕获任何类型的错误/异常

Fatal error: Call to undefined function dacicontratosBundleCommandejecutar()
in C:DropboxApache Xamppevaluacion_dacisrcdacicontratosBundleCommandSegu
imientosRemainderEmailCommand.php on line 82

你知道是怎么回事吗?

PHP基础:try{} catch(){}块只能捕获Exception抛出的错误。

你没有在这里粘贴错误日志(请粘贴),但我认为这是一个致命的错误,或某种。

请记住,这些错误是不可捕获的。因此,即使在try-catch中,它们也会破坏脚本

最新更新