summaryrefslogtreecommitdiff
path: root/java/12-error-handling-2
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/12-error-handling-2
parent530141c542ab3b44991f05016e66db651795e9c9 (diff)
Renamed directory 12-error-handling-2 to 11-error-handling-2
Diffstat (limited to 'java/12-error-handling-2')
-rw-r--r--java/12-error-handling-2/.gitignore2
-rw-r--r--java/12-error-handling-2/Maths.java11
-rw-r--r--java/12-error-handling-2/MathsException.java22
-rw-r--r--java/12-error-handling-2/MathsTest.java32
-rw-r--r--java/12-error-handling-2/MathsTest2.java27
-rw-r--r--java/12-error-handling-2/MathsTest3.java21
-rw-r--r--java/12-error-handling-2/MathsTest4.java33
-rw-r--r--java/12-error-handling-2/MathsTest5.java21
-rw-r--r--java/12-error-handling-2/MathsTest6.java22
-rw-r--r--java/12-error-handling-2/MathsTest7.java22
10 files changed, 0 insertions, 213 deletions
diff --git a/java/12-error-handling-2/.gitignore b/java/12-error-handling-2/.gitignore
deleted file mode 100644
index e493dd6..0000000
--- a/java/12-error-handling-2/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-bin
-dist
diff --git a/java/12-error-handling-2/Maths.java b/java/12-error-handling-2/Maths.java
deleted file mode 100644
index b61a9f2..0000000
--- a/java/12-error-handling-2/Maths.java
+++ /dev/null
@@ -1,11 +0,0 @@
-public class Maths {
-
- public int factorial(int number) throws MathsException {
- if (number < 0) {
- MathsException e = new MathsException("Factorial of " + number + " not defined");
-// e.setX(100);
- throw e;
- }
- return number == 0 ? 1 : number * factorial(number - 1);
- }
-}
diff --git a/java/12-error-handling-2/MathsException.java b/java/12-error-handling-2/MathsException.java
deleted file mode 100644
index bdbaf81..0000000
--- a/java/12-error-handling-2/MathsException.java
+++ /dev/null
@@ -1,22 +0,0 @@
-public class MathsException extends Exception {
-
- public MathsException() {
- // TODO Auto-generated constructor stub
- }
-
- public MathsException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- public MathsException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
- public MathsException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
-}
diff --git a/java/12-error-handling-2/MathsTest.java b/java/12-error-handling-2/MathsTest.java
deleted file mode 100644
index 7b6827c..0000000
--- a/java/12-error-handling-2/MathsTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-public class MathsTest {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- Maths m = new Maths();
- int result = 0;
-
- try {
- m.factorial(-5);
- m.factorial(5); // Not executed
- } catch (MathsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- try {
- result = m.factorial(-5);
- // ...
- } catch(MathsException me) {
-// System.err.println(me.getX());
- System.err.println("Factorial method failed");
- } finally {
- System.out.println("Inside finally block");
- }
-
- System.out.println(result);
-
- }
-
-}
diff --git a/java/12-error-handling-2/MathsTest2.java b/java/12-error-handling-2/MathsTest2.java
deleted file mode 100644
index 4aa8b59..0000000
--- a/java/12-error-handling-2/MathsTest2.java
+++ /dev/null
@@ -1,27 +0,0 @@
-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);
- }
-
-}
diff --git a/java/12-error-handling-2/MathsTest3.java b/java/12-error-handling-2/MathsTest3.java
deleted file mode 100644
index ca45e5c..0000000
--- a/java/12-error-handling-2/MathsTest3.java
+++ /dev/null
@@ -1,21 +0,0 @@
-public class MathsTest3 {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- Maths m = new Maths();
- int result = 0;
-
- try {
- result = m.factorial(-5);
- } catch(MathsException e) {
- System.err.println("Factorial method failed");
- System.err.println(e.getMessage());
- e.printStackTrace();
- }
-
- System.out.println(result);
- }
-
-}
diff --git a/java/12-error-handling-2/MathsTest4.java b/java/12-error-handling-2/MathsTest4.java
deleted file mode 100644
index b5cca8a..0000000
--- a/java/12-error-handling-2/MathsTest4.java
+++ /dev/null
@@ -1,33 +0,0 @@
-public class MathsTest4 {
-
- /**
- * @param args
- * @throws MathsException
- */
- public static void main(String[] args) throws MathsException {
- Maths m = new Maths();
- int result = 0;
-
- // No catching! Then the method should be declared
- // to throw the exception (or a super type like
- // Exception or even Throwable)
-
-// m.factorial(5);
-
- // Look! A try block can be defined without a catch block
- // as well.
- try {
- result = m.factorial(-5);
- System.out.println("xxx");
- } finally {
- System.out.println("Inside finally block");
- }
-
- // No try block is also possible
- // Since the method is declared to duct the exception
- result = m.factorial(-5);
-
- System.out.println(result);
- }
-
-}
diff --git a/java/12-error-handling-2/MathsTest5.java b/java/12-error-handling-2/MathsTest5.java
deleted file mode 100644
index 56bf64d..0000000
--- a/java/12-error-handling-2/MathsTest5.java
+++ /dev/null
@@ -1,21 +0,0 @@
-public class MathsTest5 {
-
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception {
- Maths m = new Maths();
- int result = 0;
-
- try {
- result = m.factorial(-5);
- } catch (MathsException me) {
- throw new Exception("My exception wrapper", me);
- } finally {
- System.out.println("Inside finally block");
- }
-
- System.out.println(result);
- }
-
-}
diff --git a/java/12-error-handling-2/MathsTest6.java b/java/12-error-handling-2/MathsTest6.java
deleted file mode 100644
index 7f176aa..0000000
--- a/java/12-error-handling-2/MathsTest6.java
+++ /dev/null
@@ -1,22 +0,0 @@
-public class MathsTest6 {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- Maths m = new Maths();
- int result = 0;
-
- try {
- result = m.factorial(-5);
- } catch(MathsException me) {
- System.err.println("Factorial method failed");
- System.exit(1);
- } finally {
- System.out.println("Inside finally block");
- }
-
- System.out.println(result);
- }
-
-}
diff --git a/java/12-error-handling-2/MathsTest7.java b/java/12-error-handling-2/MathsTest7.java
deleted file mode 100644
index f55cfad..0000000
--- a/java/12-error-handling-2/MathsTest7.java
+++ /dev/null
@@ -1,22 +0,0 @@
-public class MathsTest7 {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- Maths m = new Maths();
- int result = 0;
-
- try {
- result = m.factorial(-5);
- } catch(MathsException me) {
- System.err.println("Factorial method failed");
- return;
- } finally {
- System.out.println("Inside finally block");
- }
-
- System.out.println(result);
- }
-
-}