0

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
Will
  • 6,601
  • 3
  • 31
  • 42

1 Answers1

0

Ah, found it, they are being caught and converted to runtime IllegalStateException exceptions here:

As for motivation, Spring favors runtime exceptions generally: why spring handles only unchecked exceptions

Will
  • 6,601
  • 3
  • 31
  • 42