blob: 3c7908356d4cf00ce90111fa3b815db784cec85e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http.server.jetty;
/**
* Utility methods for exceptions
*
* @author tonytv
*/
public class Exceptions {
/**
* Allows treating checked exceptions as unchecked.
* Usage:
* throw throwUnchecked(e);
* The reason for the return type is to allow writing throw at the call site
* instead of just calling throwUnchecked. Just calling throwUnchecked
* means that the java compiler won't know that the statement will throw an exception,
* and will therefore complain on things such e.g. missing return value.
*/
public static RuntimeException throwUnchecked(Throwable e) {
throwUncheckedImpl(e);
return null;
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void throwUncheckedImpl(Throwable t) throws T {
throw (T)t;
}
}
|