Bonjour, j'ai codé une mini-classe représentant une Pile, et j'aimerais savoir comment gérer le fait que la LinkedList peut être "pleine"...
J'ai donc gérer IllegalStateException, mais je ne sais pas si c'est la bonne exception à gérer...
Merci de votre aide
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 import java.util.LinkedList; import java.util.NoSuchElementException; public class PileLinkedList<T> implements IntPile<T> { private LinkedList<T> pile; public PileLinkedList() { this.pile = new LinkedList<T>(); } public void empiler(T e) throws PilePleineException { try { this.pile.addLast(e); } catch(IllegalStateException except) { throw new PilePleineException(); } } public void depiler() throws PileVideException { try { this.pile.removeLast(); } catch(NoSuchElementException except) { throw new PileVideException(); } } public T dernier() throws PileVideException { try { return this.pile.getLast(); } catch(NoSuchElementException except) { throw new PileVideException(); } } public boolean estVide() { return this.pile.isEmpty(); } }
Partager