Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 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 | * http://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 | |
| 17 | package android.hardware.photography.utils; |
| 18 | |
| 19 | /** |
| 20 | * @hide |
| 21 | */ |
| 22 | public class UncheckedThrow { |
| 23 | |
| 24 | /** |
| 25 | * Throw any kind of exception without needing it to be checked |
| 26 | * @param e any instance of a Exception |
| 27 | */ |
| 28 | public static void throwAnyException(Exception e) { |
| 29 | /** |
| 30 | * Abuse type erasure by making the compiler think we are throwing RuntimeException, |
| 31 | * which is unchecked, but then inserting any exception in there. |
| 32 | */ |
| 33 | UncheckedThrow.<RuntimeException>throwAnyImpl(e); |
| 34 | } |
| 35 | |
| 36 | @SuppressWarnings("unchecked") |
| 37 | private static<T extends Exception> void throwAnyImpl(Exception e) throws T { |
| 38 | throw (T) e; |
| 39 | } |
| 40 | } |