-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why X.class? #3
Comments
It's been a while since I wrote this code, so I don't remember the original reason (has it really been 5+ years, ouch). I think it's to maintain type-safety with the checked exception. Java doesn't let you catch/throw exceptions generically, you need an actual class instance to do it. The following isn't allowed:
Instead you have to do something like:
What did you do to get rid of the parameter in |
The cast is safe because 1) |
I'd rather be safe than sorry in that situation. Getting a Also I'm not against improving this API to make it more usable, I'm just not going to have the time to do it. I'd be happy to review PRs if you're feeling up to it |
There would be no
I don’t understand. Which problem would that cause? Also, an exception type that inherits from
Thanks for your replies so far and willingness to review. TBH currently I am rather discouraged by the size of the library. I consider implementing only pieces of it for my own use for the moment, and later perhaps release an improvement to it, or even a totally new one that would be more modest. Anyway the API would be incompatible, I suppose. Speaking of this, I am very surprised to see that Also, relatedly, you posted somewhere that your library uses Brian Goetz’s recommended approach, or something similar. I have read his opinion (voiced numerous times) against sneaky throws, but I am not aware that he recommended a specific approach to solve the problem, similar to what this library does. Do you have a pointer supporting this? I’d be most curious to read his thoughts. |
I love your approach! This is the way to go for those who, like me, don’t like sneaky throws.
I just reviewed several popular SO questions that deal with the “streams and checked exceptions” issue, and found only your library as a solution for those who want no library that sneaky throw among their dependencies, among the ones that these questions reference (though I may have missed some):
Now to my question. Why do you require a class parameter designating the exception thrown, when creating a
ThrowingStream
? This seems unnecessary to me, and makes usage less elegant from the caller’s point of view. At least, the example in the wiki can be modified so as to avoid usage of the parameterClass<X> x
in theStreamAdapter
constructor (I just did it). Is there something that has escaped me?The text was updated successfully, but these errors were encountered: