异常处理
来源:互联网 发布:图像空间的消隐算法 编辑:程序博客网 时间:2024/06/16 16:42
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<?php
error_reporting(E_ALL);
class text{
protected $conn=null;
public function __construct(){
$this->conn=mysql_connect('localhost','root','r1oot');//这里故意写错:)
if (!$this->conn) {
$e=new Exception('错误',001);1,new Exception('错误原因','错误代码') 2.Exception是所有异常的基类。
throw $e;
}
}
}
try {
$a=new text();
$e->getCode(),'<br/>',
$e->getFile(),'<br/>',
$e->getLine(),'<br/>';
}
print_r($a);
if ($a instanceof text) {
echo '对象创建成功,连接成功';
}
<?php
error_reporting(E_ALL);
class text{
protected $conn=null;
public function __construct(){
$this->conn=mysql_connect('localhost','root','r1oot');//这里故意写错:)
if (!$this->conn) {
$e=new Exception('错误',001);1,new Exception('错误原因','错误代码') 2.Exception是所有异常的基类。
throw $e;
}
}
}
try {
$a=new text();
}
catch (Exception $e) {
echo $e->getMessage(),'<br/>',$e->getCode(),'<br/>',
$e->getFile(),'<br/>',
$e->getLine(),'<br/>';
}
print_r($a);
if ($a instanceof text) {
echo '对象创建成功,连接成功';
}
else{echo '对象创建失败,连接失败';}
抛出异常后,对象未创建成功
0 0
- 异常处理+异常+处理异常+自定义异常
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 异常处理
- 69.二叉树的层次遍历
- [kuangbin带你飞]专题十一 网络流 D POJ – 2195
- javascript怎么把对象里的数据整合进另外一个数组里
- 圆的面积
- 各种坑的合集
- 异常处理
- 1017. A除以B (20)
- 网上图书商城视频教程day01
- xml文件的读写
- Struts-OGNL-3
- 分页实现
- JavaScript语言精粹(一)(词法作用域,JSON及其服务器处理,document.write()与document.writeln()区别)
- jquery eval解析JSON中的注意点介绍
- ECMAScript引用类型之Array类型