Created
December 13, 2012 20:35
-
-
Save szarnekow/4279571 to your computer and use it in GitHub Desktop.
Musings about checked exceptions in Xtend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static extension Throwables.* | |
val uri = [| new URI(requestURI) ].onException [ | |
new IllegalArgumentException(it) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
URI uri = new URI(requestUri); | |
.. | |
} catch (URISyntaxException e) { | |
throw new RuntimeException(e); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URI uri = Throwables.propagate( | |
() -> new URI(requestUri)); | |
// or even | |
URI uri = Throwables.propagate( | |
() -> new URI(requestUri), | |
IllegalArgumentException::new); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URI uri = Throwables.propagate( | |
() -> new URI(requestUri), | |
(e) -> new IllegalArgumentException(e)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Throwables { | |
def static <T> T onException( | |
()=>T proc, | |
(Exception)=>Exception handler) { | |
try { | |
proc.apply | |
} catch(Exception e) { | |
throw handler.apply(e) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val uri = new URI(requestURI) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment