summaryrefslogtreecommitdiff
path: root/java/11-error-handling-2/MathsTest2.java
diff options
context:
space:
mode:
authorKamal Wickramanayake <kamal@inbox.lk>2026-02-22 19:31:37 +0530
committerKamal Wickramanayake <kamal@inbox.lk>2026-02-22 19:31:37 +0530
commitae4cf7c9f0a0b90d02166b43402e67b7d4ad4dca (patch)
treeac50c582a3600917ce9e4eee0387995c2615ec28 /java/11-error-handling-2/MathsTest2.java
parent530141c542ab3b44991f05016e66db651795e9c9 (diff)
Renamed directory 12-error-handling-2 to 11-error-handling-2
Diffstat (limited to 'java/11-error-handling-2/MathsTest2.java')
-rw-r--r--java/11-error-handling-2/MathsTest2.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/java/11-error-handling-2/MathsTest2.java b/java/11-error-handling-2/MathsTest2.java
new file mode 100644
index 0000000..4aa8b59
--- /dev/null
+++ b/java/11-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);
+ }
+
+}