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) {
36
36
* @throws T dummy declaration to satisfy the compiler
37
37
*/
38
38
@ 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 {
40
40
// Due to generic type erasure, this cast only serves to satisfy the compiler
41
41
// that the requirement to declare the thrown exception has been met.
42
42
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