If it's only because of the encoding then you can add a comment in the catch block to note why this exception is ignored and don't try to manually build the URL. The documentation of the URI constructor states that a URISyntaxException is thrown when the resulting URI violates a RFC, so I'd rather print an exception and return null or don't catch that exception in that method at all, but let it be handled by the calling method.