Licence Informatique Année 2005-2006. Exceptions



Similar documents
Langages Orientés Objet Java

Remote Method Invocation

POB-JAVA Documentation

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

TP N 10 : Gestion des fichiers Langage JAVA

Introduction. GEAL Bibliothèque Java pour écrire des algorithmes évolutionnaires. Objectifs. Simplicité Evolution et coévolution Parallélisme

Brazil + JDBC Juin 2001, douin@cnam.fr

Sun Management Center Change Manager Release Notes

«Object-Oriented Multi-Methods in Cecil» Craig Chambers (Cours IFT6310, H08)

N1 Grid Service Provisioning System 5.0 User s Guide for the Linux Plug-In

Solaris 10 Documentation README

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Liste d'adresses URL

Programmation Orientée Objets. et langage Java

Memory Eye SSTIC Yoann Guillot. Sogeti / ESEC R&D yoann.guillot(at)sogeti.com

Sun Enterprise Optional Power Sequencer Installation Guide

Upgrading the Solaris PC NetLink Software

How To Become A Foreign Language Teacher

Solutions Premiers Pas

Optimizing and interfacing with Cython. Konrad HINSEN Centre de Biophysique Moléculaire (Orléans) and Synchrotron Soleil (St Aubin)

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

The Register of the Domain of the State A Revolution in the Registration of Land Rights

SunFDDI 6.0 on the Sun Enterprise Server

TP : Système de messagerie - Fichiers properties - PrepareStatement

Les fragments. Programmation Mobile Android Master CCI. Une application avec deux fragments. Premier layout : le formulaire

Calcul parallèle avec R

sept-2002 Computer architecture and software cells for broadband networks Va avec

NUNAVUT HOUSING CORPORATION - BOARD MEMBER RECRUITMENT

Sun StorEdge A5000 Installation Guide

Sun StorEdge RAID Manager Release Notes

Note concernant votre accord de souscription au service «Trusted Certificate Service» (TCS)

Sun Cluster 2.2 7/00 Data Services Update: Apache Web Server

Short Form Description / Sommaire: Carrying on a prescribed activity without or contrary to a licence

Optimizing Solaris Resources Through Load Balancing


Sun Management Center 3.5 Update 1b Release Notes

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

ENABLING OBJECTIVE AND TEACHING POINTS. DRILL: TIME: One 30 minutes period. 6. METHOD/APPROACH: a. demonstration; and. b. performance.

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Service Level Definitions and Interactions

Technical Service Bulletin

In-Home Caregivers Teleconference with Canadian Bar Association September 17, 2015

6 e. Sciences. Tests de rendement provinciaux de l Alberta. année. Points saillants sur l évaluation 2009

Interfaces de programmation pour les composants de la solution LiveCycle ES (juillet 2008)

MD. ALI KHAN. and THE MINISTER OF CITIZENSHIP AND IMMIGRATION REASONS FOR ORDER AND ORDER

Web - Travaux Pratiques 1

Programmation RMI Sécurisée

Évariste Galois and Solvable Permutation Groups

Veritas Storage Foundation 5.0 Software for SPARC

Sun StorEdge N8400 Filer Release Notes

Hours: The hours for the class are divided between practicum and in-class activities. The dates and hours are as follows:

Introduction au BIM. ESEB Seyssinet-Pariset Economie de la construction contact@eseb.fr

Finding a research subject in educational technology

niveau : 1 ere année spécialité : mécatronique & froid et climatisation AU : Programmation C Travaux pratiques

STUDENT APPLICATION FORM (Dossier d Inscription) ACADEMIC YEAR (Année Scolaire )

Introduction ToIP/Asterisk Quelques applications Trixbox/FOP Autres distributions Conclusion. Asterisk et la ToIP. Projet tuteuré

ESMA REGISTERS OJ/26/06/2012-PROC/2012/004. Questions/ Answers

Office of the Auditor General / Bureau du vérificateur général FOLLOW-UP TO THE 2010 AUDIT OF COMPRESSED WORK WEEK AGREEMENTS 2012 SUIVI DE LA

TIMISKAMING FIRST NATION

Le(s) auteur(s) par la presente cede(nt) a. I'IFIP en toute exclusivite et dans tous les pays tous les droits relatifs a. l'oeuvre

FINAL DRAFT INTERNATIONAL STANDARD

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.

Service Level Agreement in the Data Center

How To Read An Islamic

Il est repris ci-dessous sans aucune complétude - quelques éléments de cet article, dont il est fait des citations (texte entre guillemets).

DHI a.s. Na Vrsich 51490/5, , Prague 10, Czech Republic ( t.metelka@dhi.cz, z.svitak@dhi.cz )


Personnalisez votre intérieur avec les revêtements imprimés ALYOS design

Générer des graphiques 3D - Cours Université de Sfax

Java Dynamic Management Architecture for Intelligent Networks

Creating a Simple, Multithreaded Chat System with Java

In France. page 2. In Belgium. page 3. In Germany. page 4. In Greece page 5

Measuring Policing Complexity: A Research Based Agenda

Archived Content. Contenu archivé

System Requirements Orion

Annexe - OAuth Introduction. Xavier de Rochefort xderoche@labri.fr - labri.fr/~xderoche 15 mai 2014

Group Projects M1 - Cubbyhole

Scrubbing Disks Using the Solaris Operating Environment Format Program

How To Find Out How Roots Of A Polynome Are Calculated

Introduction to Object-Oriented Programming

Solaris 9 9/05 Installation Roadmap

Archived Content. Contenu archivé

Troncatures dans les modèles linéaires simples et à effets mixtes sous R

Archived Content. Contenu archivé

J a v a Quiz (Unit 3, Test 0 Practice)

Sun Management Center 3.6 Version 5 Add-On Software Release Notes

CFT ICT review Questions/Answers

St. Edward s University

Archived Content. Contenu archivé

Comparing JavaServer Pages Technology and Microsoft Active Server Pages

Sun StorEdge Availability Suite Software Point-in-Time Copy Software Maximizing Backup Performance

Archived Content. Contenu archivé

Audit de sécurité avec Backtrack 5

Archived Content. Contenu archivé

"Internationalization vs. Localization: The Translation of Videogame Advertising"

Sun N1 Service Provisioning System User s Guide for Linux Plug-In 2.0

Transcription:

Université Paris 7 Java Licence Informatique Année 2005-2006 TD n 8 - Correction Exceptions Exercice 1 La méthode parseint est spécifiée ainsi : public static int parseint(string s) throws NumberFormatException Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign - ( \u002d ) to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseint(java.lang.string, int) method. Parameters: s - a String containing the int representation to be parsed Returns: the integer value represented by the argument in decimal. Throws: NumberFormatException - if the string does not contain a parsable integer. Utiliser cette fonction pour faire la somme de tous les entiers donnés en argument de la ligne de commande, les autres arguments étant ignorés. Correction : class Somme { public static void main(string[] args) { int somme = 0; for(int i=0;i<args.length;i++) { somme += Integer.parseInt(args[i]); catch (NumberFormatException e) { System.out.println(somme); Exercice 2 Écrire une classe Pile qui implémente une pile d objets avec un tableau de taille fixe. On définira pour cela deux exceptions PilePleine et pilevide. On utilisera pour écrire les méthodes, l exception ArrayOutOfBoundsException qui indique qu on a tenté d accéder à une case non définie d un tableau. Les champs de la classe seront : 1

private final static int taille = 10; private Object [] pile; private int pos; Écrire une méthode main qui empile les arguments de la ligne de commande (du moins tant que c est possible) et qui les réécrit dans l ordre inverse. On aura par exemple : > java Pile 1 2 3 4 5 6 7 8 9 10 11 12 13 10 9 8 7 6 5 4 3 2 1 Correction : class PilePleine extends Exception{ PilePleine(String s) { class PileVide extends Exception{ PileVide(String s) { class Pile{ private final static int taille = 10; private Object [] pile; private int pos; Pile() { pile=new Object[taille]; pos=0; public void empile(object o) throws PilePleine{ pile[pos]=o; pos++; catch(arrayindexoutofboundsexception e){ throw new PilePleine("Pile pleine!"); public Object depile() throws PileVide{ Object o = pile[pos-1]; pos--; return o; catch(arrayindexoutofboundsexception e){ throw new PileVide("Pile vide!"); public static void main(string[] args){ Pile p = new Pile(); for(int i=0;i<args.length;i++) p.empile(args[i]); 2

catch(pilepleine e) {; for(;;) System.out.print(p.depile()+" "); catch(pilevide e) { System.out.println(); 3

Exercice 3 1. Que fait le programme suivant? class Essai1Exception extends Exception{ Essai1Exception (String s){ class Essai2Exception extends Essai1Exception{ Essai2Exception (String s){ class Exn{ static void throwessais(int i) throws Exception { switch(i){ case 1: System.out.println("Lancement de Essai1Exception"); throw new Essai1Exception("Essai1Exception de throwessais"); case 2: System.out.println("Lancement de Essai2Exception"); throw new Essai2Exception("Essai2Exception de throwessais"); default: System.out.println("Lancement de Exception"); throw new Exception("Exception de throwessais"); public static void main(string[] args){ for(int i=1; i<=3;i++){ try{ throwessais(i); catch(essai2exception e){ System.out.println("Catch Essai2 : "+e.getmessage()); catch(essai1exception e){ System.out.println("Catch Essai1 : "+e.getmessage()); catch(exception e){ System.out.println("Catch Exception : "+e.getmessage()); finally{ System.out.println("Finally de main"); 4

2. Et celui-ci? class Essai1Exception extends Exception{ Essai1Exception (String s){ class Essai2Exception extends Essai1Exception{ Essai2Exception (String s){ class Exn{ static void throwessais(int i) throws Exception { switch(i){ case 1: System.out.println("Lancement de Essai1Exception"); throw new Essai1Exception("Essai1Exception de throwessais"); case 2: System.out.println("Lancement de Essai2Exception"); throw new Essai2Exception("Essai2Exception de throwessais"); default: System.out.println("Lancement de Exception"); throw new Exception("Exception de throwessais"); public static void main(string[] args){ for(int i=1; i<=3;i++){ try{ throwessais(i); catch(essai1exception e){ System.out.println("Catch Essai1 : "+e.getmessage()); catch(essai2exception e){ System.out.println("Catch Essai2 : "+e.getmessage()); catch(exception e){ System.out.println("Catch Exception : "+e.getmessage()); finally{ System.out.println("Finally de main"); 5

Correction : 1. Lancement de Essai1Exception Catch Essai1 : Essai1Exception de throwessais Finally de main Lancement de Essai2Exception Catch Essai2 : Essai2Exception de throwessais Finally de main Lancement de Exception Catch Exception : Exception de throwessais Finally de main 2. problème à la compilation : Exn.java:22: exception Essai2Exception has already been caught catch(essai2exception e){ ^ 1 error 6