1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Catch Throwable in PHP 7

This commit is contained in:
Benjamin Morel 2016-04-21 23:33:34 +02:00 committed by Marco Pivetta
parent 8c7052c99c
commit 874a5e3547
No known key found for this signature in database
GPG Key ID: 4167D3337FD9D629
7 changed files with 38 additions and 10 deletions

View File

@ -19,7 +19,6 @@
namespace Doctrine\ORM;
use Exception;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
@ -237,7 +236,12 @@ use Doctrine\Common\Util\ClassUtils;
$this->conn->commit();
return $return ?: true;
} catch (Exception $e) {
} catch (\Throwable $e) {
$this->close();
$this->conn->rollBack();
throw $e;
} catch (\Exception $e) { // PHP 5
$this->close();
$this->conn->rollBack();

View File

@ -129,11 +129,15 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor
foreach ($this->_sqlStatements as $sql) {
$conn->executeUpdate($sql);
}
} catch (\Exception $exception) {
} catch (\Throwable $exception) {
// FAILURE! Drop temporary table to avoid possible collisions
$conn->executeUpdate($this->_dropTempTableSql);
// Re-throw exception
throw $exception;
} catch (\Exception $exception) { // PHP 5
$conn->executeUpdate($this->_dropTempTableSql);
throw $exception;
}

View File

@ -188,11 +188,15 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
$conn->executeUpdate($statement, $paramValues, $paramTypes);
}
} catch (\Exception $exception) {
} catch (\Throwable $exception) {
// FAILURE! Drop temporary table to avoid possible collisions
$conn->executeUpdate($this->_dropTempTableSql);
// Re-throw exception
throw $exception;
} catch (\Exception $exception) { // PHP 5
$conn->executeUpdate($this->_dropTempTableSql);
throw $exception;
}

View File

@ -72,7 +72,11 @@ EOT
if ($input->getOption('complete') !== null) {
$em->getConnection()->connect();
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return 1;
} catch (\Exception $e) { // PHP 5
$output->writeln('<error>' . $e->getMessage() . '</error>');
return 1;

View File

@ -92,7 +92,9 @@ class SchemaTool
foreach ($createSchemaSql as $sql) {
try {
$conn->executeQuery($sql);
} catch (\Exception $e) {
} catch (\Throwable $e) {
throw ToolsException::schemaToolFailure($sql, $e);
} catch (\Exception $e) { // PHP 5
throw ToolsException::schemaToolFailure($sql, $e);
}
}
@ -742,7 +744,9 @@ class SchemaTool
foreach ($dropSchemaSql as $sql) {
try {
$conn->executeQuery($sql);
} catch (\Exception $e) {
} catch (\Throwable $e) {
} catch (\Exception $e) { // PHP 5
}
}

View File

@ -30,11 +30,11 @@ class ToolsException extends ORMException
{
/**
* @param string $sql
* @param \Exception $e
* @param \Exception $e The original exception, or duck-typed Throwable in PHP 7.
*
* @return ToolsException
*/
public static function schemaToolFailure($sql, \Exception $e)
public static function schemaToolFailure($sql, $e)
{
return new self("Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, "0", $e);
}

View File

@ -44,6 +44,7 @@ use Doctrine\ORM\Persisters\Entity\SingleTablePersister;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\ORM\Utility\IdentifierFlattener;
use Exception;
use Throwable;
use InvalidArgumentException;
use UnexpectedValueException;
@ -411,7 +412,14 @@ class UnitOfWork implements PropertyChangedListener
}
$conn->commit();
} catch (Exception $e) {
} catch (\Throwable $e) {
$this->em->close();
$conn->rollBack();
$this->afterTransactionRolledBack();
throw $e;
} catch (\Exception $e) { // PHP 5
$this->em->close();
$conn->rollBack();