Skip to content

Instantly share code, notes, and snippets.

@konecny
Created July 8, 2012 10:52
Show Gist options
  • Save konecny/3070495 to your computer and use it in GitHub Desktop.
Save konecny/3070495 to your computer and use it in GitHub Desktop.
<?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