无法捕获PHP中抛出的COM异常

时间:2014-05-09 17:29:04

标签: php laravel com

我一直在寻找谷歌和堆栈溢出永远试图解决这个问题。

我似乎无法捕捉异常com_exception

public function get($pc){
    try{
        $this->com = new \COM ("WbemScripting.SWbemLocator");
        $WbemServices = $this->com->ConnectServer($pc, $this->com_path, $this->username, $this->password);
    } catch(com_exception $e){
        return false;
    }

    $WbemServices->Security_->ImpersonationLevel = 3;

    $disks =  $WbemServices->ExecQuery("Select * from Win32_LogicalDisk");

    return $this->format_disk($disks); //Returns disk data in a nice format
}

$this->com是一个私有变量。我目前正在使用该功能检索我网络中服务器PC上的磁盘空间,它运行良好,但如果输入的PC在网络上不存在则抛出异常。

无论我做什么,我总是收到Whoops屏幕:

com_exception
<b>Source:</b> SWbemLocator<br/><b>Description:</b> The RPC server is unavailable.

非常感谢任何帮助!如果您需要更多细节,请告诉我。

1 个答案:

答案 0 :(得分:0)

我想当你在PHP中的命名空间类中时,你需要反斜杠它们才能注册:

catch(\com_exception $e){

而不是:

catch(com_exception $e){

这解决了我的问题。

相关问题