2

When I ran my batch file and get Excetion below:

enter image description here

I try to catch exception but I can not catch. My code sample is below:

/**
 * {@inheritdoc}
 */
protected function execute(InputInterface $input, OutputInterface $output)
{
    try {
        $sql = '';
        $connection = $this->_resource->getConnection();
        $result = $connection->fetchAll($sql);
        ....
        }
    catch (Exception $e) {
        $this->writeErrorLog($e->getMessage());
    }
}

But I can't not get message of Exception. So that, Anyone show me How to get message of Exception to write log?

1 Answer 1

4

you can execute Magento2 commands with the '-vvv' switch to get the debug output.

bin/magento batch:creteo -vvv

Also, if your class is in a namespace and you did not import the \Exception class (just assuming, can't see that in your example), it has to be \Exception in the catch block. Otherwise it will be searched for in your current namespace

/**
 * {@inheritdoc}
 */
protected function execute(InputInterface $input, OutputInterface $output)
{
    try {
        $sql = '';
        $connection = $this->_resource->getConnection();
        $result = $connection->fetchAll($sql);
        ....
        }
    catch (\Exception $e) {
        $this->writeErrorLog($e->getMessage());
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.