Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';捕获PHP中引发的COM异常_Php_Laravel_Com - Fatal编程技术网

Can';捕获PHP中引发的COM异常

Can';捕获PHP中引发的COM异常,php,laravel,com,Php,Laravel,Com,我一直在google和stack overflow中寻找答案 我似乎无法捕捉异常com\u异常 public function get($pc){ try{ $this->com = new \COM ("WbemScripting.SWbemLocator"); $WbemServices = $this->com->ConnectServer($pc, $this->com_path, $this->username, $

我一直在google和stack overflow中寻找答案

我似乎无法捕捉异常
com\u异常

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在网络上不存在,它会抛出异常

无论我做什么,我都会收到带有以下内容的欢呼屏幕:

com_exception
<b>Source:</b> SWbemLocator<br/><b>Description:</b> The RPC server is unavailable.
com\u异常
来源:SWbemLocator
描述:RPC服务器不可用。

非常感谢您的帮助!如果您需要更多详细信息,请让我知道。

我想当您在PHP中使用名称空间类时,您需要反斜杠异常,以便他们注册:

catch(\com\u异常$e){

而不是:

catch(com_异常$e){

这解决了我的问题