[ea593a3] | 1 | // Throw Across Other Handler |
---|
| 2 | |
---|
| 3 | class EmptyException extends Exception {} |
---|
| 4 | |
---|
| 5 | class NotRaisedException extends Exception {} |
---|
| 6 | |
---|
| 7 | public class ThrowOther { |
---|
| 8 | static boolean should_throw = false; |
---|
| 9 | |
---|
| 10 | private static void unwind_other(int frames) |
---|
| 11 | throws EmptyException, NotRaisedException { |
---|
| 12 | if (0 < frames) { |
---|
| 13 | try { |
---|
| 14 | unwind_other(frames - 1); |
---|
| 15 | } catch (NotRaisedException e) { |
---|
| 16 | // ... |
---|
| 17 | } |
---|
[e4da70b] | 18 | } else if (should_throw) { |
---|
| 19 | throw new NotRaisedException(); |
---|
[ea593a3] | 20 | } else { |
---|
| 21 | throw new EmptyException(); |
---|
| 22 | } |
---|
| 23 | } |
---|
| 24 | |
---|
[11d4fa5] | 25 | private static long loop(int times, int total_frames) { |
---|
[ee23a8d] | 26 | long startTime = System.nanoTime(); |
---|
[ea593a3] | 27 | for (int count = 0 ; count < times ; ++count) { |
---|
| 28 | try { |
---|
| 29 | unwind_other(total_frames); |
---|
| 30 | } catch (EmptyException e) { |
---|
| 31 | // ... |
---|
| 32 | } catch (NotRaisedException e) { |
---|
| 33 | // ... |
---|
| 34 | } |
---|
| 35 | } |
---|
[ee23a8d] | 36 | long endTime = System.nanoTime(); |
---|
[11d4fa5] | 37 | return endTime - startTime; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | public static void main(String[] args) { |
---|
| 41 | int times = 1; |
---|
| 42 | int total_frames = 1; |
---|
| 43 | if (0 < args.length) { |
---|
| 44 | times = Integer.parseInt(args[0]); |
---|
| 45 | } |
---|
| 46 | if (1 < args.length) { |
---|
| 47 | total_frames = Integer.parseInt(args[1]); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | // Warm-Up: |
---|
| 51 | loop(1000, total_frames); |
---|
| 52 | |
---|
| 53 | long time = loop(times, total_frames); |
---|
[f79ee0d] | 54 | System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.); |
---|
[ea593a3] | 55 | } |
---|
| 56 | } |
---|