-
-
Save konecny/3070495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyException extends Exception | |
{ | |
private $method; | |
private $exception; | |
function __construct($method, $exception) { | |
$this->method = $method; | |
$this->exception = $exception; | |
} | |
function process() { | |
return $this->method . ": " . $this->exception->getCode(); | |
} | |
} | |
class X { | |
function neco() { | |
try { | |
$pdo = new PDO("sqlite:test.db", null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); | |
$pdo->query("INSERT INTO test(num) VALUES (10)"); // sloupec 'num' je unikátní a záznam s hodnotou 10 již existuje | |
} catch (PDOException $e) { | |
throw new MyException(__METHOD__, $e); | |
} | |
} | |
} | |
try { | |
$x = new X; | |
$x->neco(); | |
} catch (MyException $e) { | |
echo $e->process(); | |
} | |
?> | |
--------- | |
Result: X::neco: 23000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment