I have started to delve more into the world of exceptions and due to the lack of documentation on this topic I wouldn't mind some opinion.
I have extended the standard Exception class just to allow logging of the errors.
Am I going about this in the right way or should I be looking at a different technique?
public function __construct()
{
$this->db = new database::getInstance();
}
public function gallery($gallery)
{
try
{
//ignore the query it's incomplete
if (!$stmt = $this->db->prepare("SELECT g.id, g.caption, g.image, g.thumb, gr.title, WHERE g.main='1' AND gr.live='1' AND g.live='1' AND g.delete!='1' AND gr.delete!='1' AND gr.url=? ORDER BY gr.order ASC"))
{
throw new mException($this->db->error, $this->db->error_no);
}
$stmt->bind_param('s', $gallery);
if (!$stmt->execute())
{
throw new mException($stmt->error, $stmt->error_no);
}
$stmt->bind_result($this->id, $this->caption, $this->image, $this->thumb, $this->title);
while ($stmt->fetch())
{
$array[] = $this->objectToArray();
}
}
catch (mException $e)
{
$e->errorLog(); // Echo error if in debug mode else save data to flat file or database
}
}
I have also started to put together a replacement for the standard error reporting using the ErrorException class
function exceptionErrorHandler($errno, $errstr, $errfile, $errline )
{
try
{
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
catch (ErrorException $e)
{
try
{
throw new mException($e->message, $e->number);
}
catch (mException $m)
{
$e->errorLog();
}
}
}
The code it's self is the simple thing I have no problem with that technique is the one thing I always question.
All opinion is greatly appreciated.