source:
doc/theses/andrew_beach_MMath/code/TryFinally.java
@
41870a5
Last change on this file since 41870a5 was f79ee0d, checked in by , 3 years ago | |
---|---|
|
|
File size: 639 bytes |
Rev | Line | |
---|---|---|
[f79ee0d] | 1 | // Enter and Leave a Try Statement with a Finally Handler |
[ea593a3] | 2 | |
[f79ee0d] | 3 | public class TryFinally { |
[11d4fa5] | 4 | private static boolean shouldThrow = false; |
[ea593a3] | 5 | |
[11d4fa5] | 6 | private static long loop(int times) { |
[ee23a8d] | 7 | long startTime = System.nanoTime(); |
[ea593a3] | 8 | for (int count = 0 ; count < times ; ++count) { |
9 | try { | |
10 | // ... | |
11 | } finally { | |
12 | // ... | |
13 | } | |
14 | } | |
[ee23a8d] | 15 | long endTime = System.nanoTime(); |
[11d4fa5] | 16 | return endTime - startTime; |
17 | } | |
18 | ||
19 | public static void main(String[] args) { | |
20 | int times = 1; | |
21 | if (0 < args.length) { | |
22 | times = Integer.parseInt(args[0]); | |
23 | } | |
24 | ||
25 | // Warm-Up: | |
26 | loop(1000); | |
27 | ||
28 | long time = loop(times); | |
[f79ee0d] | 29 | System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.); |
[ea593a3] | 30 | } |
31 | } |
Note: See TracBrowser
for help on using the repository browser.