source:
doc/theses/andrew_beach_MMath/code/TryFinally.java@
b9fe89b
| Last change on this file since b9fe89b was f79ee0d, checked in by , 5 years ago | |
|---|---|
|
|
| File size: 639 bytes | |
| Line | |
|---|---|
| 1 | // Enter and Leave a Try Statement with a Finally Handler |
| 2 | |
| 3 | public class TryFinally { |
| 4 | private static boolean shouldThrow = false; |
| 5 | |
| 6 | private static long loop(int times) { |
| 7 | long startTime = System.nanoTime(); |
| 8 | for (int count = 0 ; count < times ; ++count) { |
| 9 | try { |
| 10 | // ... |
| 11 | } finally { |
| 12 | // ... |
| 13 | } |
| 14 | } |
| 15 | long endTime = System.nanoTime(); |
| 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); |
| 29 | System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.); |
| 30 | } |
| 31 | } |
Note:
See TracBrowser
for help on using the repository browser.