-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtutorial_46.java
30 lines (27 loc) · 940 Bytes
/
tutorial_46.java
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
/**
* CLASS
*/
class Calculator {
//
public static void main(String[] args) {
int[] nums = new int[] { 12, 5, 3, 0 };
try {
int result = intDivide( 18, nums[3] );
System.out.println( "The answer is " + result );
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println( "This index is not available." );
} catch (java.lang.ArithmeticException e) {
System.out.println( "Cannot divide by zero." );
}
// this last catch is only useful if you do something besides just throw the error.
catch (Exception e) {
// do something here like log it out to a text file or something.
throw e;
}
System.out.println("Continue on with the program.");
}
//
static int intDivide( int n1, int n2 ) {
return ( n1 / n2 );
}
}