-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrowthrowsfinally.java
More file actions
44 lines (44 loc) · 1016 Bytes
/
Copy paththrowthrowsfinally.java
File metadata and controls
44 lines (44 loc) · 1016 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
import java.io.*;
import java.util.Scanner;
class MyException extends Exception
{
MyException (String message)
{
super (message);
}
}
class Operation
{
float divide (int a, int b) throws MyException
{
float c = (float)a/(float)b;
if (c<0.01)
throw new MyException ("Numerator is too small");
return c;
}
}
class Main
{
public static void main (String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter 2 Numbers: ");
int a = sc.nextInt();
int b = sc.nextInt();
try
{
Operation obj = new Operation();
float ans = obj.divide(a, b);
System.out.println ("Answer: "+ans);
}
catch(MyException e)
{
System.out.println ("Caught MyException");
System.out.println (e.getMessage());
}
finally
{
System.out.println ("I'm Always Here");
}
}
}