最终异常给出了错误的PHP [英] finally exception gives an error php

查看:90
本文介绍了最终异常给出了错误的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习PHP,并且我刚刚转到Exceptions,当我
尝试从

I am trying to learn PHP, and i just moved to Exceptions and when i try a example from

= a href = http:/ /php.net/manual/en/language.exceptions.php rel = nofollow> http://php.net/manual/en/language.exceptions.php

示例#2使用finally块的异常处理

我得到一个错误

解析错误:语法错误,第13行的C:\xampp\htdocs\test\filename.php中出现意外的'{'

<?php
function inverse($x) {
    if (!$x) {
        throw new Exception('Division by zero.');
    }
    else return 1/$x;
}

try {
    echo inverse(5) . "\n";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
} finally {
    echo "First finally.\n";
}

try {
    echo inverse(0) . "\n";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
} finally {
    echo "Second finally.\n";
}

// Continue execution
echo 'Hello World';


推荐答案

最终 try-catch块已添加到PHP 5.5中,该代码仍在开发中,因此可能无法使用它的原因是因为您使用的是PHP 5.4或更早版本。

The finally block of try-catch was added in PHP 5.5 which is still in development so the likely reason it isn't working for you is because you are using PHP 5.4 or earlier.

除非他们将其反向移植到早期的PHP版本中,或者您使用的是5.5版,否则您将无法最终使用。

You won't be able to use finally unless they backport it into an earlier PHP version or you are on a 5.5 release.

这篇关于最终异常给出了错误的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆