繁体   English   中英

无法捕获PHP中引发的COM异常

[英]Can't catch COM exception thrown in PHP

我一直在寻找通过谷歌和堆栈溢出,试图找出这一点。

我似乎无法捕捉到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在网络上不存在,则会引发异常。

无论我做什么,我总是收到带有以下内容的“ Woops”屏幕:

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

任何帮助是极大的赞赏! 如果您需要更多详细信息,请告诉我。

我猜想当您在PHP的命名空间类中时,您需要反斜杠异常以便它们进行注册:

catch(\\com_exception $e){

代替:

catch(com_exception $e){

这解决了我的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM