File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
main/java/com/nordstrom/common/base
test/java/com/nordstrom/common/base Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public static RuntimeException throwUnchecked(final Throwable thrown) {
3636 * @throws T dummy declaration to satisfy the compiler
3737 */
3838 @ SuppressWarnings ("unchecked" )
39- private static <T extends Exception > void propagate (Throwable thrown ) throws T {
39+ private static <T extends Throwable > void propagate (Throwable thrown ) throws T {
4040 // Due to generic type erasure, this cast only serves to satisfy the compiler
4141 // that the requirement to declare the thrown exception has been met.
4242 throw (T ) thrown ;
Original file line number Diff line number Diff line change 1+ package com .nordstrom .common .base ;
2+
3+ import java .io .IOException ;
4+
5+ import org .testng .annotations .Test ;
6+
7+ public class UncheckedThrowTest {
8+
9+ @ Test (expectedExceptions = {IOException .class })
10+ public void testCheckedException () {
11+ try {
12+ throwCheckedException ();
13+ } catch (Throwable t ) {
14+ throw UncheckedThrow .throwUnchecked (t );
15+ }
16+ }
17+
18+ @ Test (expectedExceptions = {AssertionError .class })
19+ public void testUncheckedException () {
20+ try {
21+ throwUncheckedException ();
22+ } catch (Throwable t ) {
23+ throw UncheckedThrow .throwUnchecked (t );
24+ }
25+ }
26+
27+ private void throwCheckedException () throws IOException {
28+ throw new IOException ("This is a checked exception" );
29+ }
30+
31+ private void throwUncheckedException () {
32+ throw new AssertionError ("This is an unchecked exception" );
33+ }
34+
35+ }
You can’t perform that action at this time.
0 commit comments