summaryrefslogtreecommitdiff
path: root/java/11-error-handling-2/MathsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/11-error-handling-2/MathsTest.java')
-rw-r--r--java/11-error-handling-2/MathsTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/java/11-error-handling-2/MathsTest.java b/java/11-error-handling-2/MathsTest.java
new file mode 100644
index 0000000..7b6827c
--- /dev/null
+++ b/java/11-error-handling-2/MathsTest.java
@@ -0,0 +1,32 @@
+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);
+
+ }
+
+}