1
0
mirror of synced 2025-02-13 10:49:25 +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; namespace Doctrine\ORM;
use Exception;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
@ -237,7 +236,12 @@ use Doctrine\Common\Util\ClassUtils;
$this->conn->commit(); $this->conn->commit();
return $return ?: true; return $return ?: true;
} catch (Exception $e) { } catch (\Throwable $e) {
$this->close();
$this->conn->rollBack();
throw $e;
} catch (\Exception $e) { // PHP 5
$this->close(); $this->close();
$this->conn->rollBack(); $this->conn->rollBack();

View File

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

View File

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

View File

@ -72,7 +72,11 @@ EOT
if ($input->getOption('complete') !== null) { if ($input->getOption('complete') !== null) {
$em->getConnection()->connect(); $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>'); $output->writeln('<error>' . $e->getMessage() . '</error>');
return 1; return 1;

View File

@ -92,7 +92,9 @@ class SchemaTool
foreach ($createSchemaSql as $sql) { foreach ($createSchemaSql as $sql) {
try { try {
$conn->executeQuery($sql); $conn->executeQuery($sql);
} catch (\Exception $e) { } catch (\Throwable $e) {
throw ToolsException::schemaToolFailure($sql, $e);
} catch (\Exception $e) { // PHP 5
throw ToolsException::schemaToolFailure($sql, $e); throw ToolsException::schemaToolFailure($sql, $e);
} }
} }
@ -742,7 +744,9 @@ class SchemaTool
foreach ($dropSchemaSql as $sql) { foreach ($dropSchemaSql as $sql) {
try { try {
$conn->executeQuery($sql); $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 string $sql
* @param \Exception $e * @param \Exception $e The original exception, or duck-typed Throwable in PHP 7.
* *
* @return ToolsException * @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); 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\Proxy\Proxy;
use Doctrine\ORM\Utility\IdentifierFlattener; use Doctrine\ORM\Utility\IdentifierFlattener;
use Exception; use Exception;
use Throwable;
use InvalidArgumentException; use InvalidArgumentException;
use UnexpectedValueException; use UnexpectedValueException;
@ -411,7 +412,14 @@ class UnitOfWork implements PropertyChangedListener
} }
$conn->commit(); $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(); $this->em->close();
$conn->rollBack(); $conn->rollBack();