-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.java
More file actions
30 lines (27 loc) · 813 Bytes
/
Copy pathDriver.java
File metadata and controls
30 lines (27 loc) · 813 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
public class Driver{
public static void main(String[] args) {
Thing a = new Thing();
BetterThing b = new BetterThing();
//Code with no error handling
for(int i = 0 ; i < 30; i++){
a.work(i);
}
//code that stops after 1 error
for(int i = 0 ; i < 30; i++){
try{ //code that might have an Exception
b.work(i);
}catch(Exception e){ //what to do if there is an Exception
e.printStackTrace();//show the error
System.exit(1);//exit the program. Try commenting this out!
}
}
try{ //code that might have an Exception
for(int i = 0 ; i < 30; i++){
b.work(i);
}
}catch(Exception e){ //what to do if there is an Exception
e.printStackTrace();
System.exit(1);//do not continue the program
}
}
}