如何捕获[Symfony \ Component \ Debug \ Exception \ ContextErrorException]

I'm trying to make a php command using symfony to connect through ssh to a server. It's all okay, but if i can't connect to server (server unreachable) i take this error :

[Symfony\Component\Debug\Exception\ContextErrorException]             
Warning: ssh2_connect(): Unable to connect to skin-master on port 22  

This is okay but if i try to catch the error doing something like this:

try{
                $exec=$this->ssh_connect($cinema);
            }
            catch(\Exception $e){
                echo $e;
                $this->no_connection($em,$cinema);
                continue;

I continue to have the error so i can't control this exception. How can I do this? Thanks :)

simply catch the exception explicitly

try {

} catch (\Symfony\Component\Debug\Exception\ContextErrorException $e) {

}

if you need to catch other exceptions as well you can do it like this

try {

} catch (\Symfony\Component\Debug\Exception\ContextErrorException $e) {

} catch (\Some\Other\Exception $e) {

} catch (\Exception $e) {

}

To check a connection. You can use:

http://php.net/manual/en/function.fsockopen.php