From 28b4b8a98506c16aa996f20653ac704d9b1dc49f Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Fri, 29 May 2015 09:39:25 +0200 Subject: [PATCH] move all exception declaration to their own file --- exceptions.php | 49 +++++++++++++++++++++++++++++++++++++++++++ global.php | 1 + lib/AudioBook.php | 6 ------ lib/Connection.php | 16 -------------- lib/DbMapping.php | 6 ------ mobile.webservice.php | 21 ------------------- 6 files changed, 50 insertions(+), 49 deletions(-) create mode 100644 exceptions.php diff --git a/exceptions.php b/exceptions.php new file mode 100644 index 0000000..28b9d6e --- /dev/null +++ b/exceptions.php @@ -0,0 +1,49 @@ +excname = $name; + parent::__construct($reason, $code); + } + + public function getName() + { + return $this->excname; + } +} + +class SqlException extends Exception +{ + private $query; + + public function __construct($message = "Sql Error", $query = "") + { + $this->query = $query; + parent::__construct($message, 0); + } + + public function getSqlError() + { + return $this->getMessage().' while executing: '.$this->query; + } +} + +class BookNotFoundException extends WebException { + public function __construct($code) { + parent::__construct('BookNotFound', "The book with code $code was not found", -404); + } +} + +/** + * Exception raised when an invalid attribute name is accessed + */ +class InvalidAttributeException extends Exception { } diff --git a/global.php b/global.php index 209a6d1..1900ebf 100644 --- a/global.php +++ b/global.php @@ -1,4 +1,5 @@ query = $query; - parent::__construct($message, 0); - } - - public function getSqlError() - { - return $this->getMessage().' while executing: '.$this->query; - } -} - class OdbcResultSet implements Iterator, ArrayAccess { public $length; diff --git a/lib/DbMapping.php b/lib/DbMapping.php index a4b87ed..416c763 100644 --- a/lib/DbMapping.php +++ b/lib/DbMapping.php @@ -120,9 +120,3 @@ abstract class DbMapping return $result; } } - - -/** - * Exception raised when an invalid attribute name is accessed - */ -class InvalidAttributeException extends Exception { } diff --git a/mobile.webservice.php b/mobile.webservice.php index 135d268..1e587dc 100644 --- a/mobile.webservice.php +++ b/mobile.webservice.php @@ -1,26 +1,5 @@ excname = $name; - parent::__construct($reason, $code); - } - - public function getName() - { - return $this->excname; - } -} - abstract class WebService { private $func = null;