Bonjour,
Je suis débutante dans la gestion des exceptions et je rencontre un problème dans mon main.
J'ai une méthode connection qui envoie une erreur qui pointe sur mon fichiers ClientLDAPException.java.
Ensuite, dans mon main, si je saisis un uid erroné, il m'affiche une liste d'erreurs que j'aimerais récupérer pour afficher un message plus compréhensible.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 public void connection (String url, String dn, String psw) throws ch.ldap.ClientLDAPException { Hashtable<String,String> env; env = new Hashtable<String,String>(); env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put (Context.PROVIDER_URL, url); env.put (Context.SECURITY_AUTHENTICATION, "simple"); env.put (Context.SECURITY_PRINCIPAL, dn); env.put (Context.SECURITY_CREDENTIALS, psw); try { ctx = new InitialDirContext(env); } catch ( javax.naming.NamingException e ) { throw new ch.esnig.ldap.ClientLDAPException("Error : Initialisation du context LDAP! (connection)", e ); } }
Comme il semble dire que l'erreur est de type "javax.naming.InitialContext", je la "catche", mais ça ne doit pas être la bonne technique.
Voici les 2 erreurs rencontrées :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public static void main(String[] args) throws ch.ldap.ClientLDAPException { String dn = "uid=bidon,ou=personne,dc=ecole,dc=ch"; String psw = "xxx"; String url = "ldap://localhost:389"; ClientLDAP client = new ClientLDAP(); try { client.connection (url, dn, psw); } catch (javax.naming.InitialContext e) { // System.out.println ("Probleme du credential"); throw new ch.esnig.ldap.ClientLDAPException("Reported error : Credential! (main)", e ); } //client.printAttributes(dn); //client.disconnection(); } }
- cannot find symbol symbol : constructor ClientLDAPException(java.lang.String,javax.naming.InitialContext)
location: class ch.esnig.ldap.ClientLDAPException
throw new ch.ldap.ClientLDAPException("Reported error : Credential! (ma
in)", e );
Comme je ne suis pas trop expérimentée dans la gestion des erreurs, je ne comprends ce que ça veut dire.
Est-ce qu'une bonne âme pourrait m'aider ?
Merci d'avance.
Partager