Can';捕获PHP中引发的COM异常
我一直在google和stack overflow中寻找答案 我似乎无法捕捉异常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, $
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){
这解决了我的问题