IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Erreurs avec try et catch


Sujet :

Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 131
    Points : 44
    Points
    44
    Par défaut Erreurs avec try et catch
    bonjour tout le monde,

    j'ai ce code java avec lequel je trouve quelques soucis :
    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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
     
    package evaluation;
    import Similarity.*;
    import Similarity.sim_ling;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.net.URL;
    //import de.uma.alignment.matcher.demo.DemoMatcher;
    import eu.sealsproject.platform.res.domain.omt.IOntologyMatchingToolBridge;
    import eu.sealsproject.platform.res.tool.api.ToolBridgeException;
    import eu.sealsproject.platform.res.tool.api.ToolException;
    import eu.sealsproject.platform.res.tool.api.ToolType;
    import eu.sealsproject.platform.res.tool.impl.AbstractPlugin;
     
    public class MatcherBridge extends AbstractPlugin implements IOntologyMatchingToolBridge {
    /**
    * Aligns to ontologies specified via their URL and retunrs the
    * URL of the resulting alignment, which should be stored locally.
    *
    */
    public URL align(URL source, URL target)throws ToolBridgeException, ToolException {
            //DemoMatcher demoMatcher;
        sim_ling sim ;
            try {
                sim= new sim_ling(source.toURI(), target.toURI());
            try {
                String alignmentString = sim.align(source.toURI(), target.toURI());
            try {
                File alignmentFile = File.createTempFile("alignment", ".rdf");
                FileWriter fw = new FileWriter(alignmentFile);
            fw.write(alignmentString);
            fw.flush();
            fw.close();
            return alignmentFile.toURI().toURL();
                }
            catch (IOException e) {
            throw new ToolBridgeException("cannot create file for results", e);
            }
            }
            catch (URISyntaxException e1) {
            throw new ToolBridgeException("cannot convert the input param to URI");
            }
            }
            catch (NumberFormatException e2) {
            throw new ToolBridgeException("cannot read from configuration file", e2);
            }
            /*catch (IOException e3) {
            throw new ToolBridgeException("cannot access configuration file", e3);
            }*/
    }
    /**
    * This functionality is not supported by the tool. In case
    * it is invoked a ToolException is thrown.
    */
    public URL align(URL source, URL target, URL inputAlignment)
    throws ToolBridgeException, ToolException {
    throw new ToolException("functionaility of called method is not supported");
    }
    /**
    * In our case the DemoMatcher can be executed on the fly. In case
    * prerequesites are required it can be checked here.
    */
    public boolean canExecute() {
    return true;
    }
    /**
    * The DemoMatcher is an ontology matching tool. SEALS supports the
    * evaluation of different tool types like e.g., reasoner and storage systems.
    */
    public ToolType getType() {
    return ToolType.OntologyMatchingTool;
    }
    }
    mon erreur est au niveau de cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     sim= new sim_ling(source.toURI(), target.toURI());
    on me propose comme solution soit de la blocker ou la borner avec un try/catch
    et quand je suis la proposition ça me donne ce catch:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    catch (URISyntaxException ex) {
                    Logger.getLogger(MatcherBridge.class.getName()).log(Level.SEVERE, null, ex);
    je fais quoi? j'ai peur que ce catch nuira à l'exécution de mon programme

  2. #2
    Modérateur

    Avatar de Robin56
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juin 2009
    Messages
    5 297
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Juin 2009
    Messages : 5 297
    Points : 13 670
    Points
    13 670
    Par défaut
    Citation Envoyé par ebenmous Voir le message
    mon erreur est au niveau de cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     sim= new sim_ling(source.toURI(), target.toURI());
    on me propose comme solution soit de la blocker ou la borner avec un try/catch
    et quand je suis la proposition ça me donne ce catch:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    catch (URISyntaxException ex) {
                    Logger.getLogger(MatcherBridge.class.getName()).log(Level.SEVERE, null, ex);
    je fais quoi? j'ai peur que ce catch nuira à l'exécution de mon programme
    Question : Connais tu le principe d'un Try .. Catch ?

    Sans TryCatch voici ce qu'il peut se passer :
    - Ton URI est mal formée au niveau de la source ou de la target et ton programme lance une exception (une URISyntaxException). Elle n'est pas rattrapée et donc se propage jusqu'à la sortie d'erreur. C'est pas très beau et ça peut poser problème.
    Avec TryCatch, voici ce qu'il va se passer :
    - Ton URI est mal formée au niveau de la source ou de la target et ton programme lance une exception (une UISyntaxException). Cette exception est "attrapée" dans ce bloc et une action correctrice ou une alerte est lancée pour signaler le problème. En l’occurrence ici, une alerte est inscrite dans les logs pour prévenir du problème.

    Donc non ça ne nuira pas à ton programme, ça sera même bénéfique puisque ça te permettra de localiser les erreurs produites et d'agir en conséquence.
    Responsable Java de Developpez.com (Twitter et Facebook)
    Besoin d'un article/tutoriel/cours sur Java, consulter la page cours
    N'hésitez pas à consulter la FAQ Java et à poser vos questions sur les forums d'entraide Java
    --------
    Architecte Solution
    LinkedIn : https://www.linkedin.com/in/nicolascaudard/

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 131
    Points : 44
    Points
    44
    Par défaut
    bien reçu et merciiiiiiiii c'est gentil )))

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 24/04/2012, 14h34
  2. erreur avec try dans un autre try
    Par dadal56 dans le forum JDBC
    Réponses: 0
    Dernier message: 30/04/2010, 00h27
  3. Gestion des erreurs avec le try catch
    Par shaun_the_sheep dans le forum Général Java
    Réponses: 8
    Dernier message: 03/03/2010, 10h22
  4. probleme avec try et catch
    Par salsero1 dans le forum Struts 1
    Réponses: 2
    Dernier message: 15/11/2007, 08h02
  5. Besoin d'aide avec try catch
    Par LeBigornot dans le forum C++
    Réponses: 12
    Dernier message: 01/06/2007, 23h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo