Question

I've been looking through google and stack overflow forever trying to figure this out.

I can't seem to catch the exception 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 is a private variable. I'm currently using the function to retrieve disk space on server PC's in my network, and it works great, but if the PC entered doesn't exist on the network it throws the exception.

No matter what I do, I always receive the Whoops screen with:

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

Any help is greatly appreciated! If you need more detail please let me know.

Was it helpful?

Solution

I guess when your in a namespaced class in PHP you need to backslash exceptions for them to register:

catch(\com_exception $e){

instead of:

catch(com_exception $e){

This solved my issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top