PHP&Yii2; 如何使N尝试连接到LDAP而不显示错误

Good morning, I need to understand how to handle the following problem with Yii2.

I have to connect to an LDAP server that sometimes, quite randomly, does not respond for a few milliseconds. My idea was to handle a number of attempts before returning an error and blocking the code.

The main problem is that at the first connection refused the code stops responding showing the error. Is there a way to bypass error handling only for this function? The connection code is as follows:

`   protected $connection=false;
    protected $bind=false;
    protected $host_ip="192.168.10.190";
    protected $host=false;
    protected $username_admin="username";
    protected $password_admin="password";
    protected $ou="OU=MyUsers";
    protected $dc="DC=MyDomain,DC=network";
    protected $domain="MyDomain.network";

    protected $maxConnectionAttempts=5;

    public function connect()
    {
        if(!$this->connection)
        {

            for($attempts=0;$attempts<$this->maxConnectionAttempts;$attempts++){
                echo "<br>try to connect ...";
                $this->connection = ldap_connect("ldaps://".$this->host_ip);
                try{
                    $this->bind = ldap_bind($this->connection,$this->username_admin."@".$this->domain,$this->password_admin);
                }catch(Exception $e){

                }

                if($this->bind){
                    $attempts=$this->maxConnectionAttempts;
                }
                //@ 3th attempt i set the correct IP of LDAP
                if($attempts==2){
                    $this->host_ip="192.168.10.19";
                }
            }             
        }
    }

}`

Thank you in advance for any suggestion!