He does not raise an exception, he complains that you have failed in what he can, although he wonโt, because the URL in this case is not distorted. (The Java designers thought this concept, โchecked exceptions,โ was a good idea, although it didnโt work well in practice.)
To close it, add MalformedURLException throws or its superclass will throw an IOException in the method declaration. For instance:
public void myMethod() throws IOException { URL url = new URL("https://wikipedia.org/"); }
Alternatively, catch and reconstruct the annoying exception as an uncontrolled exception
public void myMethod() { try { URL url = new URL("https://wikipedia.org/"); ... } catch (IOException e) { throw new RuntimeException(e); } }
source share