安静
PHP技术博客

180731 php catch error层级

非trycatch 下的throw 异常


class ab{
	
	public function gg(){
		// try{
			if(1!=2){
				echo "run is 1!=2".PHP_EOL;
				throw new Exception("Error Processing Request", 1);
			}
		// }catch(Exception $e){
		// 	echo "run back".PHP_EOL;
		// }
	}	

	public function __destruct() {
        print "Destroying " . self::class . "\n";
    }
}


$ab=new ab();
$ab->gg();

执行结果


run is 1!=2
PHP Fatal error:  Uncaught Exception: Error Processing Request in /Users/ab/Sites/try.php:8
Stack trace:
#0 /Users/ab/Sites/try.php(22): ab->gg()
#1 {main}
  thrown in /Users/ab/Sites/try.php on line 8

Fatal error: Uncaught Exception: Error Processing Request in /Users/ab/Sites/try.php:8
Stack trace:
#0 /Users/ab/Sites/try.php(22): ab->gg()
#1 {main}
  thrown in /Users/ab/Sites/try.php on line 8
FAIL: 255

trycatch 下的 throw异常


class ab{
	
	public function gg(){
		try{
			if(1!=2){
				echo "run is 1!=2".PHP_EOL;
				throw new Exception("Error Processing Request", 1);
			}
		 }catch(Exception $e){
		 	echo "run back".PHP_EOL;
		 }
	}	

	public function __destruct() {
        print "Destroying " . self::class . "\n";
    }
}


$ab=new ab();
$ab->gg();

执行结果


run is 1!=2
run back
Destroying ab

赞(0) 打赏
未经允许不得转载:AJ's Blog » 180731 php catch error层级
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏