为什么我无法捕捉异常

时间:2015-04-26 13:39:12

标签: javascript php symfony exception mpd

我有一个简单的php库https://github.com/MonsterGfx/PHP-MPD-Client

我的symfony2工作正常,但直到mpd服务器脱机。 我想检查一下mpd状态 -

static function checkSource(\MDS\SiteBundle\Entity\Source $source)
{
    try {
        MPD::connect($source->getMpdpassword(), $source->getMpdhost(), $source->getMpdport());
    } catch (MPDConnectionFailedException $e) {
        return false;
    }
    $ping = MPD::send("ping");
    if ($ping['status'] == 'OK') {
        return true;
    } else {
        return false;
    }
}

问题是当服务器脱机时,我会抛出

Warning: fsockopen(): unable to connect to planeset.ru:6600 (Connection refused) 500 Internal Server Error - ContextErrorException

但我必须抓住错误。我看到了库中的代码

if(!static::$fp)
{
// no connection
 throw new MPDConnectionFailedException("$errstr ($errno)");
}

为什么我无法捕获错误并出现500错误?我做错了什么?

0 个答案:

没有答案
相关问题