Page 1 of 1

Exceptions problems

Posted: Fri Sep 08, 2006 9:06 am
by someberry
Ok, so I have read the PHP manual and tried out their examples, but I cant for the life of me just make it come out with an error such as:

Code: Select all

DBError: You do not seem to have database permission.
It always comes out as:

Code: Select all

Fatal error: Uncaught DBError: You do not seem to have database permission. thrown in D:\localhost\htdocs\classes\Connection.class.html on line 45
This is the code I am using:

DBError class

Code: Select all

class DBError extends Exception
{
	function __construct($message)
	{
		parent::__construct($message, 0);
	}
	
	public function __toString()
	{
		return  __CLASS__ . ': ' . $this->message;
	}
}
Connection.class.html

Code: Select all

$this -> connection = @mysql_connect ('localhost', 'user', 'password', true);
		
if(!$this -> connection)
{
	throw new DBError('You do not seem to have database permission.');
}
Does anyone know why it is doing this?

Thanks,
someberry.

Posted: Fri Sep 08, 2006 9:39 am
by GM
thrown exceptions should be caught:

Code: Select all

function myFunctionThatThrowsAnError() {
      throw new DBException('Not Authorised');
}

try {
      myFunctionThatThrowsAnError();
}

catch (DBException $e) {
      die "Caught: ".$e->getMessage();
}

//continue...