Traitement des exceptions
Bonjour a tous,
Je traite les exceptions de la facon suivante
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public class A{
public void methodeA()
throws OscarException
{
try
{
...
if(erreur)
throw new OscarException("A", "methodeA", "message");
}
catch (Exception e)
{
e.printStackTrace();
logger.error("Erreur inconnue: " + e.getMessage());
throw new OscarException("A", "methodeA", "cause A");());
}
}
}
public class B{
public void methodeB()
throws OscarException
{
try
{
....
instanceDeA.methodeA();
}
catch (Exception e)
{
e.printStackTrace();
logger.error("Erreur inconnue: " + e.getMessage());
throw new OscarException("B", "methodeB", "cause B");());
}
}
} |
De cette facon je traite toutes les exceptions possibles dans chaque methode.
Le probleme c'est que si une OscarException se produit dans methodeA, la methodeB
la catch (catch (Exception e) ) et la renvoie en tant que nouvelle OscarException.
Du coup ca masque l'origine du probleme.
Comme l'OscarException provient forcement de la methodeA je me propose d'ajouter
ceci dans methodeB:
catch(OscarException e)
{
throw e;
}
Ainsi, toutes les exceptions sont traitées (j'ai tj mon catch (Exception e) )
Et je regle mon probleme.
Qu'en pensez vous, est ce une bonne maniere de traiter les Exceptions ?
Merci
Sebastien
Sébastien RAGONS
DSIV OX PQ
ext.osiatis.ragons@sncf.fr
22.52.07 / 03.28.55.62.07