Introducing a tiny library for throwing Java exceptions: Cy Young
A little library from the engineering team at Launchable, so you can throw any exception from anywhere, like the man himself.
Key Takeaways
Launchable's made it easier to throw exceptions in Java.
With Cy Young, you can throw any exception from anywhere
Available in Maven central
We have deep open source roots at Launchable. From the countless open-source libraries and programs we use every day to make Launchable run, to my own experience with Jenkins and the Jenkins community. When we have a chance to give back to the community it feels good. Today, I'd like to share a tiny little library that we recently open-sourced for making it easier to throw exceptions in Java.
If you're a Java developer, from time to time you run into a situation where you want to be able to throw a checked exception from a context that you can't. For example, stream processing:
1public void reportData(Stream<Foo> foos) {
2 foos.map(this:report).collect(toList());
3}
4
5
6public Bar report(Foo foo) {
7 // what are you going to do with IOException!?
8 try (OutputStream o = new FileOutputStream(foo.fileName)) {
9 ...
10 }
11}
Man, if only you could throw any exception from anywhere!
With Cy Young, you can throw any exception from anywhere, like the man himself.
1public void reportData(Stream<Foo> foos) throws IOException {
2 foos.map(this:report).collect(toList());
3}
4
5
6public Bar report(Foo foo) {
7 try {
8 try (OutputStream o = new FileOutputStream(foo.fileName)) {
9 ...
10 }
11 } catch(IOException e) {
12 CyYoung.pitch(e); // Cy Young with throw an exception for you
13 }
14}
Handy when you are squeezed between a rock and a hard place. I think about this as "duct tape" that allows you to move on to work on things that really matter.
A little library from the engineering team at Launchable, now available in Maven central:
<groupId>com.launchableinc</groupId>
<artifactId>cyyoung</artifactId>
<version>1.0</version>