代码如下:
$this->resConn = mysql_connect ($CONFIGS['db_host'], $CONFIGS['db_user'], $CONFIGS['db_pwd']);
if (false == is_resource($this->resConn))
throw new DBException('数据库连接失败。'.mysql_error($this->resConn));
4、业务逻辑一瞥:
代码如下:
if (0 != strcmp($curAlbum->interest_id, $it))
throw new NotFoundException('很抱歉,你所访问的相册不存在');
以上就是PHP自定义异常处理器的具体使用方法.
php实例代码如下:
代码如下:
<?php
class customException extends Exception
{
public function errorMessage()
{
//error message
$errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile()
.': <b>'.$this->getMessage().'</b> is not a valid E-Mail address';
return $errorMsg;
}
}
$email = "someone@example.com";
try
{
//check if
if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE)
{
//throw exception if email is not valid
throw new customException($email);
}
//check for "example" in mail address
if(strpos($email, "example" !== FALSE)
{
throw new Exception("$email is an example e-mail"
}
}