-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionTest.java
More file actions
161 lines (111 loc) · 2.31 KB
/
Copy pathExceptionTest.java
File metadata and controls
161 lines (111 loc) · 2.31 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import java.util.Scanner;
public class ExceptionTest {
public static void main(String[] args) {
System.out.println("Begin main");
try
{
int i = new Scanner(System.in).nextInt();
System.out.println("i "+i);
int j = new Scanner(System.in).nextInt();
System.out.println("j "+j);
int k= i/j;
System.out.println("k "+k);
}
catch(Exception e)
{
System.out.println("Cant devide by zero...."+e);
}
Messaging m = new Messaging();
m.printMessage();
System.out.println("End main");
}
}
class Messaging
{
String str;
void printMessage()
{
try
{
System.out.println("str "+str.toUpperCase());
System.out.println("3rd letter in "+str+" is "+str.charAt(3));
}
catch(NullPointerException ex)
{
System.out.println("Exception is :"+ex);
}
}
}
/*
Exception = runtime error
Errors
|
---------------------------------------
| | | | |
compile runtime linker fatal logical
| | | | |
syntax Exceptions library JVM 4+4=16
Object
|
------------------
|
Throwable
|
----------------
| |
Error Exception
|(checked)
---------------------------
|
RuntimeException
| (unchecked)
---------------------
|
ArithmeticException
checked - by the compiler
unchecked - by the compiler
try { } catch() { } finally { }
throws
void fundTransfer(sa, ta, amt)
1. check the presense of ta
if ta found
then
2. check the presense of sa
if sa found
then
3. check the balance at sa
if sa is suff balance
then
4. sa.withdraw
5. ta.deposit
else
sa insufficient balance
else
sa not found
else
ta not found
---------------
void fundTransfer(sa, ta, amt)
{
try
{
1. check the presense of ta
2. check the presense of sa
3. check the balance at sa
4. sa.withdraw
5. ta.deposit
}
catch(if ta not found)
{
ta not found
}
catch(if sa not found)
{
sa not found
}
catch(if sa with insuff bal)
{
sa insufficient balance
}
Java Documentation
*/