Coder Social home page Coder Social logo

javaexception's People

Contributors

abezacier avatar

Watchers

 avatar  avatar

javaexception's Issues

Correction

Acquis. Bon travail, mais code à optimiser et à corriger (printStackTrace, code qui lève des exceptions dans certains cas...).

Ca c'est interdit ! On verra dans le prochain cours comment utiliser les loggers, en attendant, fait un System.out.println avec un message d'erreur clair.


Si ta ligne est vide, ce code plante

throw new BatchException("Type d'employé inconnu : " + ligne.charAt(0));

Tu split la ligne mais tu ne t'en sers pas

Commence par tester le nombre de champs de ta ligne pour éviter de lever une exception en cas d'accès direct à un indice du tableau qui n'existe pas. Utilise une constante pour ta regex (comme tu l'as fait précédemment)

String[] tabCommercial = ligneCommercial.split(",");
if (tabCommercial[0].matches("^[C]{1}.*") && !tabCommercial[0].matches(REGEX_MATRICULE_COMMERCIAL)) {

Problème à la fin de ton message d'erreur. Utilise les constantes dans les messages

"La chaîne " + tabCommercial[0] + " ne respecte pas l'expression régulière ^[MTC][0-9]{5}$C12");

throw new BatchException("La ligne commercial ne contient pas 7 éléments mais " + tabCommercial.length);

C'est un peu le fouillis dans tes tests, il y en a qui sont redondants, cette partie serait à réécrire plus proprement

if (tabCommercial[0].matches(REGEX_MATRICULE_COMMERCIAL) && tabCommercial.length != NB_CHAMPS_COMMERCIAL) {
throw new BatchException("La ligne commercial ne contient pas 7 éléments mais " + tabCommercial.length);
}
if (tabCommercial[0].matches(REGEX_MATRICULE_COMMERCIAL) && tabCommercial.length == NB_CHAMPS_COMMERCIAL) {

Ces instruction sont exécutées pour tous les types d'employés, ce serait donc intéressant de les regrouper dans une fonction au lieu de copier/coller.

String CaAnnuel = tabCommercial[5];
try {
Double.parseDouble(CaAnnuel);
} catch (Exception e) {
throw new BatchException(
tabCommercial[5] + "n'est pas un nombre valide pour Chiffre d'affaire annuel ");
}
try {
Integer.parseInt(tabCommercial[6]);
}catch(Exception e ) {
throw new BatchException("La performance du commercial est incorrecte : " + tabCommercial[6]);
}
String salaireCommercial = tabCommercial[4];
try {
Double.parseDouble(salaireCommercial);
} catch (Exception e) {
throw new BatchException(tabCommercial[4] + "n'est pas un nombre valide pour un salaire ");
}
String dateEmbaucheCommercial = tabCommercial[3];
try {
DateTimeFormat.forPattern("dd/MM/yyyy").parseLocalDate(dateEmbaucheCommercial);
} catch (Exception e) {
throw new BatchException(tabCommercial[3] + " ne respecte pas le format de date dd/MM/yyyy");
}

Tu as déjà fait les parse avant, c'est dommage de les refaire. Mets-les directement dans des variables pour les réutiliser lors de la construction de l'instance d'employé.

String nom = tabCommercial[1];
String prenom = tabCommercial[2];
String matriculeCommercial = tabCommercial[0];
LocalDate date = DateTimeFormat.forPattern("dd/MM/yyyy").parseLocalDate(dateEmbaucheCommercial);
Double salaire = Double.parseDouble(salaireCommercial);
Double CaAnnuelCommercial = Double.parseDouble(CaAnnuel);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.