Browse Source

Removed duplicate handling for \Throwable and \Exception

tags/3.0.0-alpha1
Alexander Makarov 7 years ago
parent
commit
f475affaeb
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A
  1. 7
      framework/base/ErrorHandler.php
  2. 7
      framework/base/View.php
  3. 9
      framework/db/ActiveRecord.php
  4. 20
      framework/db/Connection.php
  5. 10
      framework/db/Migration.php
  6. 7
      framework/db/Transaction.php
  7. 2
      framework/log/SyslogTarget.php
  8. 2
      framework/log/Target.php

7
framework/base/ErrorHandler.php

@ -116,11 +116,8 @@ abstract class ErrorHandler extends Component
}
exit(1);
}
} catch (\Exception $e) {
// an other exception could be thrown while displaying the exception
$this->handleFallbackExceptionMessage($e, $exception);
} catch (\Throwable $e) {
// additional check for \Throwable introduced in PHP 7
// additional check for \Throwable
$this->handleFallbackExceptionMessage($e, $exception);
}
@ -129,7 +126,7 @@ abstract class ErrorHandler extends Component
/**
* Handles exception thrown during exception processing in [[handleException()]].
* @param \Exception|\Throwable $exception Exception that was thrown during main exception processing.
* @param \Throwable $exception Exception that was thrown during main exception processing.
* @param \Exception $previousException Main exception processed in [[handleException()]].
* @since 2.0.11
*/

7
framework/base/View.php

@ -329,13 +329,6 @@ class View extends Component
try {
require($_file_);
return ob_get_clean();
} catch (\Exception $e) {
while (ob_get_level() > $_obInitialLevel_) {
if (!@ob_end_clean()) {
ob_clean();
}
}
throw $e;
} catch (\Throwable $e) {
while (ob_get_level() > $_obInitialLevel_) {
if (!@ob_end_clean()) {

9
framework/db/ActiveRecord.php

@ -470,9 +470,6 @@ class ActiveRecord extends BaseActiveRecord
$transaction->commit();
}
return $result;
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
} catch (\Throwable $e) {
$transaction->rollBack();
throw $e;
@ -579,9 +576,6 @@ class ActiveRecord extends BaseActiveRecord
$transaction->commit();
}
return $result;
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
} catch (\Throwable $e) {
$transaction->rollBack();
throw $e;
@ -622,9 +616,6 @@ class ActiveRecord extends BaseActiveRecord
$transaction->commit();
}
return $result;
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
} catch (\Throwable $e) {
$transaction->rollBack();
throw $e;

20
framework/db/Connection.php

@ -449,7 +449,7 @@ class Connection extends Component
* Use 0 to indicate that the cached data will never expire.
* @param \yii\caching\Dependency $dependency the cache dependency associated with the cached query results.
* @return mixed the return result of the callable
* @throws \Exception|\Throwable if there is any exception during query
* @throws \Throwable if there is any exception during query
* @see enableQueryCache
* @see queryCache
* @see noCache()
@ -461,9 +461,6 @@ class Connection extends Component
$result = call_user_func($callable, $this);
array_pop($this->_queryCacheInfo);
return $result;
} catch (\Exception $e) {
array_pop($this->_queryCacheInfo);
throw $e;
} catch (\Throwable $e) {
array_pop($this->_queryCacheInfo);
throw $e;
@ -489,7 +486,7 @@ class Connection extends Component
* @param callable $callable a PHP callable that contains DB queries which should not use query cache.
* The signature of the callable is `function (Connection $db)`.
* @return mixed the return result of the callable
* @throws \Exception|\Throwable if there is any exception during query
* @throws \Throwable if there is any exception during query
* @see enableQueryCache
* @see queryCache
* @see cache()
@ -501,9 +498,6 @@ class Connection extends Component
$result = call_user_func($callable, $this);
array_pop($this->_queryCacheInfo);
return $result;
} catch (\Exception $e) {
array_pop($this->_queryCacheInfo);
throw $e;
} catch (\Throwable $e) {
array_pop($this->_queryCacheInfo);
throw $e;
@ -715,7 +709,7 @@ class Connection extends Component
* @param callable $callback a valid PHP callback that performs the job. Accepts connection instance as parameter.
* @param string|null $isolationLevel The isolation level to use for this transaction.
* See [[Transaction::begin()]] for details.
* @throws \Exception|\Throwable if there is any exception during query. In this case the transaction will be rolled back.
* @throws \Throwable if there is any exception during query. In this case the transaction will be rolled back.
* @return mixed result of callback function
*/
public function transaction(callable $callback, $isolationLevel = null)
@ -728,9 +722,6 @@ class Connection extends Component
if ($transaction->isActive && $transaction->level === $level) {
$transaction->commit();
}
} catch (\Exception $e) {
$this->rollbackTransactionOnLevel($transaction, $level);
throw $e;
} catch (\Throwable $e) {
$this->rollbackTransactionOnLevel($transaction, $level);
throw $e;
@ -981,7 +972,7 @@ class Connection extends Component
* @param callable $callback a PHP callable to be executed by this method. Its signature is
* `function (Connection $db)`. Its return value will be returned by this method.
* @return mixed the return value of the callback
* @throws \Exception|\Throwable if there is any exception thrown from the callback
* @throws \Throwable if there is any exception thrown from the callback
*/
public function useMaster(callable $callback)
{
@ -989,9 +980,6 @@ class Connection extends Component
$this->enableSlaves = false;
try {
$result = call_user_func($callback, $this);
} catch (\Exception $e) {
$this->enableSlaves = true;
throw $e;
} catch (\Throwable $e) {
$this->enableSlaves = true;
throw $e;

10
framework/db/Migration.php

@ -109,10 +109,6 @@ class Migration extends Component implements MigrationInterface
return false;
}
$transaction->commit();
} catch (\Exception $e) {
$this->printException($e);
$transaction->rollBack();
return false;
} catch (\Throwable $e) {
$this->printException($e);
$transaction->rollBack();
@ -138,10 +134,6 @@ class Migration extends Component implements MigrationInterface
return false;
}
$transaction->commit();
} catch (\Exception $e) {
$this->printException($e);
$transaction->rollBack();
return false;
} catch (\Throwable $e) {
$this->printException($e);
$transaction->rollBack();
@ -152,7 +144,7 @@ class Migration extends Component implements MigrationInterface
}
/**
* @param \Throwable|\Exception $e
* @param \Throwable $e
*/
private function printException($e)
{

7
framework/db/Transaction.php

@ -25,19 +25,12 @@ use yii\base\InvalidConfigException;
* $connection->createCommand($sql2)->execute();
* //.... other SQL executions
* $transaction->commit();
* } catch (\Exception $e) {
* $transaction->rollBack();
* throw $e;
* } catch (\Throwable $e) {
* $transaction->rollBack();
* throw $e;
* }
* ```
*
* > Note: in the above code we have two catch-blocks for compatibility
* > with PHP 5.x and PHP 7.x. `\Exception` implements the [`\Throwable` interface](http://php.net/manual/en/class.throwable.php)
* > since PHP 7.0, so you can skip the part with `\Exception` if your app uses only PHP 7.0 and higher.
*
* @property bool $isActive Whether this transaction is active. Only an active transaction can [[commit()]] or
* [[rollBack()]]. This property is read-only.
* @property string $isolationLevel The transaction isolation level to use for this transaction. This can be

2
framework/log/SyslogTarget.php

@ -80,7 +80,7 @@ class SyslogTarget extends Target
$level = Logger::getLevelName($level);
if (!is_string($text)) {
// exceptions may not be serializable if in the call stack somewhere is a Closure
if ($text instanceof \Throwable || $text instanceof \Exception) {
if ($text instanceof \Throwable) {
$text = (string) $text;
} else {
$text = VarDumper::export($text);

2
framework/log/Target.php

@ -256,7 +256,7 @@ abstract class Target extends Component
$level = Logger::getLevelName($level);
if (!is_string($text)) {
// exceptions may not be serializable if in the call stack somewhere is a Closure
if ($text instanceof \Throwable || $text instanceof \Exception) {
if ($text instanceof \Throwable) {
$text = (string) $text;
} else {
$text = VarDumper::export($text);

Loading…
Cancel
Save