File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -179,4 +179,24 @@ static public RuntimeException runtimeException(Throwable e){
179179 return new RuntimeException (e );
180180}
181181
182+ /**
183+ * Throw even checked exceptions without being required
184+ * to declare them or catch them. Suggested idiom:
185+ * <p>
186+ * <code>throw sneakyThrow( some exception );</code>
187+ */
188+ static public RuntimeException sneakyThrow (Throwable t ) {
189+ // http://www.mail-archive.com/[email protected] /msg05984.html 190+ if (t == null )
191+ throw new NullPointerException ();
192+ Util .<RuntimeException >sneakyThrow0 (t );
193+ return null ;
194+ }
195+
196+ @ SuppressWarnings ("unchecked" )
197+ static private <T extends Throwable > void sneakyThrow0 (Throwable t ) throws T {
198+ throw (T ) t ;
182199}
200+
201+ }
202+
You can’t perform that action at this time.
0 commit comments