Skip to content

Commit 45ed41e

Browse files
committed
- Changed Exception-Handling
1 parent a14f388 commit 45ed41e

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

src/Builder/Expr/DBExprFilter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace Kir\MySQL\Builder\Expr;
33

4-
use Exception;
4+
use RuntimeException;
55

66
class DBExprFilter implements OptionalExpression {
77
/** @var mixed */
@@ -21,7 +21,6 @@ class DBExprFilter implements OptionalExpression {
2121
* @param string|string[] $keyPath
2222
* @param callable|null $validator
2323
* @param callable|null $validationResultHandler
24-
* @throws Exception
2524
*/
2625
public function __construct($expression, array $data, $keyPath, $validator = null, $validationResultHandler = null) {
2726
$this->expression = $expression;
@@ -72,14 +71,13 @@ public function getValue() {
7271
/**
7372
* @param string|string[] $keyPath
7473
* @return string
75-
* @throws Exception
7674
*/
7775
private function buildKey($keyPath) {
7876
if(is_string($keyPath)) {
7977
$keyPath = explode('.', $keyPath);
8078
}
8179
if(!is_array($keyPath)) {
82-
throw new Exception('Invalid key');
80+
throw new RuntimeException('Invalid key');
8381
}
8482
return $keyPath;
8583
}

src/Builder/Select.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Kir\MySQL\Builder\Traits\TableNameBuilder;
1212
use Kir\MySQL\Builder\Traits\UnionBuilder;
1313
use Kir\MySQL\Builder\Traits\WhereBuilder;
14+
use RuntimeException;
1415

1516
class Select extends Statement {
1617
use TableNameBuilder;
@@ -102,12 +103,11 @@ public function getCalcFoundRows() {
102103

103104
/**
104105
* @param bool $calcFoundRows
105-
* @throws \Exception
106106
* @return $this
107107
*/
108108
public function setCalcFoundRows($calcFoundRows = true) {
109109
if (ini_get("mysql.trace_mode")) {
110-
throw new \Exception('This function cant operate with mysql.trace_mode is set.');
110+
throw new RuntimeException('This function cant operate with mysql.trace_mode is set.');
111111
}
112112
$this->calcFoundRows = $calcFoundRows;
113113
return $this;

src/Databases/MySQL.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ public function transactionStart() {
269269

270270
/**
271271
* @return $this
272-
* @throws \Exception
273272
*/
274273
public function transactionCommit() {
275274
return $this->transactionEnd(function () {
@@ -279,7 +278,6 @@ public function transactionCommit() {
279278

280279
/**
281280
* @return $this
282-
* @throws \Exception
283281
*/
284282
public function transactionRollback() {
285283
return $this->transactionEnd(function () {
@@ -290,8 +288,6 @@ public function transactionRollback() {
290288
/**
291289
* @param callable|null $callback
292290
* @return mixed
293-
* @throws \Exception
294-
* @throws \Error
295291
*/
296292
public function dryRun($callback = null) {
297293
$result = null;
@@ -302,10 +298,10 @@ public function dryRun($callback = null) {
302298
$this->transactionRollback();
303299
} catch (\Exception $e) {
304300
$this->transactionRollback();
305-
throw $e;
301+
throw new RuntimeException($e->getMessage(), (int) $e->getCode(), $e);
306302
} catch (\Error $e) {
307303
$this->transactionRollback();
308-
throw $e;
304+
throw new RuntimeException($e->getMessage(), (int) $e->getCode(), $e);
309305
}
310306
} else {
311307
$uniqueId = $this->genUniqueId();
@@ -315,10 +311,10 @@ public function dryRun($callback = null) {
315311
$this->exec("ROLLBACK TO {$uniqueId}");
316312
} catch (\Exception $e) {
317313
$this->exec("ROLLBACK TO {$uniqueId}");
318-
throw $e;
314+
throw new RuntimeException($e->getMessage(), (int) $e->getCode(), $e);
319315
} catch (\Error $e) {
320316
$this->exec("ROLLBACK TO {$uniqueId}");
321-
throw $e;
317+
throw new RuntimeException($e->getMessage(), (int) $e->getCode(), $e);
322318
}
323319
}
324320
return $result;
@@ -328,8 +324,6 @@ public function dryRun($callback = null) {
328324
* @param int|callable $tries
329325
* @param callable|null $callback
330326
* @return mixed
331-
* @throws \Exception
332-
* @throws \Error
333327
*/
334328
public function transaction($tries = 1, $callback = null) {
335329
if(is_callable($tries)) {
@@ -371,7 +365,7 @@ public function transaction($tries = 1, $callback = null) {
371365
}
372366
}
373367
if($exception !== null) {
374-
throw $exception;
368+
throw new RuntimeException($exception->getMessage(), (int) $exception->getCode(), $exception);
375369
}
376370
return $result;
377371
}

0 commit comments

Comments
 (0)