DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

.k's picture

Unregistered

Feeds

aliases

  • .k

.k

1 year ago

in Evil Behavior with Unchecked Checked Exceptions on Thinking inside a bigger box
It can actually be a lot easier than Anders' example. See this http://weblogs.java.net/blog/crazybob/archive/2...
for even more clever implementations. :-)

I propose a utility-class with something like this, and we're good to go:

public static void throwUnchecked(final Throwable pException) {
// Type parameter to Thrower is erased at compile-time
new Thrower().sneakyThrow(pException);
}

private static class Thrower {
private void sneakyThrow(Throwable pException) throws T {
throw (T) pException; // Unchecked cast
}
}

I'm starting to think this might be useful.. Or... Maybe I'm just tired.. :-P


.k
Returning? Login