Hello.
I need to implement a custom Exception that extends from PDOException and thereby create some methods that return standard messages. So far I have only found unclear examples. Does anyone have a simple example?
Hello.
I need to implement a custom Exception that extends from PDOException and thereby create some methods that return standard messages. So far I have only found unclear examples. Does anyone have a simple example?
A simple example, where the MyPDOException class overrides the PDOException class, so that it can make a custom message when an error occurs using the PDO class.
class MyPDOException extends PDOException { }
class MyClass {
public function myFunction() {
try {
try {
throw new MyPDOException('Sua mensagem de erro!');
} catch (MyPDOException $e) {
throw $e;
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
}
}
$foo = new MyClass;
$foo->myFunction();