php进程中抛出异常,php – 在异常处理程序中抛出异常

你不能从异常处理程序重新抛出,但是还有其他的地方可以.例如,您可以通过将事情封装到一个自己的类中,然后使用__destruct()函数(PHP 5.3,

Demo)将处理程序重新抛出:

class ExceptionHandler

{

private $rethrow;

public function __construct()

{

set_exception_handler(array($this, 'handler'));

}

public function handler($exception)

{

echo "cleaning up.\n";

$this->rethrow = $exception;

}

public function __destruct()

{

if ($this->rethrow) throw $this->rethrow;

}

}

$handler = new ExceptionHandler;

throw new Exception();

将其放入我的错误日志中:

[29-Oct-2011 xx:32:25] PHP Fatal error: Uncaught exception 'Exception' in /.../test-exception.php:23

Stack trace:

#0 {main}

thrown in /.../test-exception.php on line 23

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值