From ae4cf7c9f0a0b90d02166b43402e67b7d4ad4dca Mon Sep 17 00:00:00 2001 From: Kamal Wickramanayake Date: Sun, 22 Feb 2026 19:31:37 +0530 Subject: Renamed directory 12-error-handling-2 to 11-error-handling-2 --- java/11-error-handling-2/MathsTest4.java | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 java/11-error-handling-2/MathsTest4.java (limited to 'java/11-error-handling-2/MathsTest4.java') diff --git a/java/11-error-handling-2/MathsTest4.java b/java/11-error-handling-2/MathsTest4.java new file mode 100644 index 0000000..b5cca8a --- /dev/null +++ b/java/11-error-handling-2/MathsTest4.java @@ -0,0 +1,33 @@ +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); + } + +} -- cgit v1.2.3