Catcher une CommunicationsException
bonjour, dans mon appli je veux détecter si le plantage de mon emf.createEntityManager() est dû à la connexion internet qui est ko.
Dailleurs, si je n'ai pas de connexion, je lève une exception :
Code:
1 2 3 4
| "Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
Error Code: 0" |
Par contre impossible de rajouter le catch CommunicationsException, netbeans me dit
Code:
1 2
| "exception com.mysql.jdbc.exceptions.jdbc4.CommunicationsException is never thrown in body of corresponding try statement
----" |
Qu est ce qui ne va pas et comment puis je détecter que l exception est due à la connexion qui ne fonctionne pas ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public static void start() throws Exception {
try{
emf = Persistence.createEntityManagerFactory("GranitosPU");
em = emf.createEntityManager();
}
catch(CommunicationsException e){
*** ici je voudrais faire mon message spécial
}
catch(Exception e){
String nl = System.getProperty("line.separator" );
throw new Exception("Erreur création E.M.F : "
+ e.getMessage()+nl+nl+"Etes vous bien connecté à internet ?");
}
} |