Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a java.net.URL.isValid()?  RSS feed

 
Daniel Näslund
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a malformed url I get a MalformedURLException when calling the constructor of java.net.URL. It would be cleaner if there was a method java.net.URL.isValid(). I haven't found one. Does anyone know of a good alternative? Right now I have my own method that encapsulates the exception throwing but perhaps there is an alternative?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. The throwng condtructor is an excellent design: it prevents a broken URL from ever being constructed. If you need a boolean check, it's easy to write one as you have found.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!