php异常实例
<?php
/**
* 这是一个数据库连接简单异常实例
* @author:PHP博客|PHP技术博客|面向对象 www.phpcq.com
*
*/
class DatabaseException extends Exception {
protected $databaseMessage;
public function __construct($messge=null,$code=0){
$this->databaseMessage = mysql_error();
parent::__construct($messge,$code);
}
public function getDatabaseErrorMessage(){
return $this->databaseMessage;
}
}
function mysqlConnect(){
if (!@ mysql_connect("localhost","root","1234561")) {
throw new DatabaseException("Fatal error!");
}
}
try {
mysqlConnect();
}
catch (DatabaseException $e){
echo $e->getMessage().'<br/>';
echo $e->getDatabaseErrorMessage();
}
?>