summaryrefslogtreecommitdiff
path: root/java/12-error-handling-2/MathsTest4.java
blob: b5cca8a1762a0d494820a2a1ea319e364b623ed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
	}

}