How do Spring's org.springframework.web.util.UriComponentsBuilder
and related UriComponents.toUri()
avoid the checked exception URISyntaxException
that occurs with the java.net.URI
constructor?
For example, using new URI()
results in having to catch the checked exception:
try {
uri = new URI(myUrl);
} catch (URISyntaxException e) {
// oops
}
vs. using Spring's builder avoids that:
uri = UriComponentsBuilder.fromUriString(myUrl)
.build()
.toUri();
// no checked exception here