PDA

View Full Version : MalformedURLException


chipdouglas
04-06-2003, 11:55 AM
Hi, I'm writing my first web browser, using java. It's at a useable stage, but I'm trying to figure out how to deal with someone typing in a non-existant URL by mistake.

So far, I'm using a try/catch with MalformedURLException, but this causes the program to quit. Obviously it would be better to display an appropriate message and let the user continue.

Is there a way to test the URL connection link beforehand?

eggman
04-10-2003, 06:56 PM
Maybe the MalformedURLException causes a non-recoverable exception. Have you tried creating your own user-defined exception class to handle it instead? That might work.


class MyException extends Exception {
public String toString() {
return "Invalid URL";
}
}

class ExceptionTest {
public static void testValue(int url) throws myException {
if(put_test_here) {
throw new MyException();
}
}

public static void main(String args[]) {
try {
testValue(a_url);
} catch (MyException e) {
System.out.println(" "+e+" caught in main");
}
System.out.println("code continues on");
}
}