| ... | ... | @@ -214,3 +214,19 @@ public void push(int element) throws StackIsFullException, NegativeElementExcept |
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# Capture et traitement d’exceptions
|
|
|
|
|
|
|
|
:book: Dans une méthode où des appels de méthode peuvent se traduire par des remontées d’exceptions et **où un traitement d’erreur est prévu** (on sait gérer l'erreur), il est obligatoire de **capturer les exceptions**, via la clause `try` / `catch` / `finally`.
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
StackOfNonNegativeIntegersWithSum stack = null;
|
|
|
|
|
|
|
|
try { stack = new StackOfNonNegativeIntegersWithSum(args[0]); }
|
|
|
|
catch (UnexpectedCapacityException e) { System.exit(1); }
|
|
|
|
|
|
|
|
System.out.println(stack.toString());
|
|
|
|
}
|
|
|
|
``` |