diff options
Diffstat (limited to 'java/12-error-handling-2/MathsTest2.java')
| -rw-r--r-- | java/12-error-handling-2/MathsTest2.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/java/12-error-handling-2/MathsTest2.java b/java/12-error-handling-2/MathsTest2.java new file mode 100644 index 0000000..4aa8b59 --- /dev/null +++ b/java/12-error-handling-2/MathsTest2.java @@ -0,0 +1,27 @@ +public class MathsTest2 { + + /** + * @param args + */ + public static void main(String[] args) { + Maths m = new Maths(); + int result = 0; + + try { + result = m.factorial(-5); + } catch(MathsException me) { // Catching a specific exception + System.err.println("Caught a MathsException"); + } catch(Exception e) { // Catching the super type + System.err.println("Caught an Exception"); + } + + try { + result = m.factorial(-5); + } catch (MathsException | ArrayIndexOutOfBoundsException e) { // Java SE 7 + + } + + System.out.println(result); + } + +} |
