1 /*
2 * Copyright 2011-2024 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.googlecode.catchexception.throwable;
17
18 /**
19 * Code borrowed from famous Spock Framework.
20 */
21 final class ExceptionUtil {
22
23 /**
24 * Prevent Instantiation of a new exception util.
25 */
26 private ExceptionUtil() {
27 // Preventing instantiation
28 }
29
30 /**
31 * Allows to throw an unchecked exception without declaring it in a throws clause.
32 *
33 * @param t
34 * throwable to throw
35 */
36 public static void sneakyThrow(Throwable t) {
37 ExceptionUtil.doSneakyThrow(t);
38 }
39
40 /**
41 * Do sneaky throw.
42 *
43 * @param <T>
44 * the generic type
45 * @param t
46 * the t
47 *
48 * @throws T
49 * the t
50 */
51 @SuppressWarnings("unchecked")
52 private static <T extends Throwable> void doSneakyThrow(Throwable t) throws T {
53 throw (T) t;
54 }
55
56 }