-1
I created a class to connect to LDAP, in one of the methods I did the following:
// Classe Ldap()
public function ldapConnection() {
$this->_ldapCon = ldap_connect($this->_ldapServer);
if ($this->_ldapCon) {
ldap_set_option($this->_ldapCon, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($this->_ldapCon, LDAP_OPT_REFERRALS, 0);
return $this->_ldapCon;
} else {
throw new Exception('Não foi possível conectar ao servidor LDAP');
}
}
If I do
$conexao = new Ldap();
try {
$conexao->ldapConnection();
} catch (Exception $ex) {
// Abaixo, não pega a exceção que eu lancei no método. A exceção lançada no método aparece como "Fatal error: Uncaught exception 'Exception' with message: Não foi possível conectar ao servidor LDAP"
echo json_encode(array('message' => $ex->getMessage()));
}
How do I get the exact exception thrown by the LDAP class method and not just a generic exception?
Not if you have anything standard you should create your custom Exception class and then capture in catch.
– rray
But the blocks
try/catch
will only evaluate the exception thrown by the method within them? Or another exception may be cast, beyond that which I myself define?– Not The Real Hemingway
The block
try/catch
given should be capturing the exception. The classLdap
is part of somenamespace
?– Woss
Yes. It’s part of
namespace Models
– Not The Real Hemingway