Écrire une fonction qui recherche un objet dans un tableau. Si l'objet est trouvé, la fonction retourne la première position où se trouve l'objet. Sinon la fonction lève une exception NoSuchElementException.
Écrire une fonction qui recherche un objet dans une liste. Si l'objet est trouvé, la fonction retourne la première cellule où se trouve l'objet. Sinon la fonction lève une exception NoSuchElementException. On pourra utiliser une exception lorsque l'objet est trouvé.
Écrire une fonction qui prend un tableau de chaînes en paramètre et qui retourne la valeur entière de la première chaîne qui peut-être lue comme un entier par la méthode parseInt. Si aucune chaîne ne peut être lue comme un entier, la fonction lève une exception NumberFormatException.
Quel est l'affichage du bout de code ci-dessous ?
class Essai1Exception extends Exception { Essai1Exception(String s) { super(s); } } class Essai2Exception extends Exception { Essai2Exception(String s) { super(s); } } class Essai3Exception extends Essai1Exception { Essai3Exception(String s) { super(s); } } class Sample { static void throwEssais(int i) throws Exception { try { switch (i) { case 1: throw new Essai1Exception("Essai1Exception de throwEssais"); case 2: throw new Essai2Exception("Essai2Exception de throwEssais"); case 3: throw new Essai3Exception("Essai3Exception de throwEssais"); default: throw new Exception("Exception de throwEssais"); } } finally { System.out.println("Finally de throwEssais"); } } public static void main(String [] args) { for (int i = 1; i < 4; i++) { try { throwEssais(i); } catch (Essai3Exception e) { System.out.println("Catch Essais3"); } catch (Essai1Exception e) { System.out.println("Catch Essais1"); } catch (Exception e) { System.out.println("Catch Exception"); } finally { System.out.println("Finally de main"); } } } }