Use custom exceptions, so we can selectively catch and extract information
CoughPhp should throw its own custom exceptions, subclasses of Exception, so code using CoughPhp can selectively catch certain types of exceptions. This would also allow the users to extract information from the exceptions by other means than parsing the message. A prime candidate for this would be the exception thrown by As_Database:
Blueprint information
- Status:
- Started
- Approver:
- None
- Priority:
- Medium
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- Approved
- Series goal:
- Accepted for 1.4
- Implementation:
- Beta Available
- Milestone target:
- 1.4
- Started by
- Anthony Bush
- Completed by
Related branches
Related bugs
Sprints
Whiteboard
An example CoughException that we could throw anywhere we currently throw Exception:
/**
* A base class for all exceptions thrown by CoughPhp. Only difference to Exception is that message is not optional.
*/
class CoughException extends Exception {
public function __construct(
}
}
And a sample CoughDatabaseEx
class CoughDatabaseEx
private $type;
private $sqlError;
private $sql;
public function __construct($type, $sqlError, $sql = "[SQL N/A]") {
parent:
$this->type = $type;
$this->sqlError = $sqlError;
$this->sql = $sql;
}
public function getType() {
return $this->type;
}
public function getSqlError() {
return $this->sqlError;
}
public function getSql() {
return $this->sql;
}
}
This would allow users to figure out the sql error that happened, and the query that was run (if any) without having to parse the message of the exception.