HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 136 Exceptions in Applets

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * See also color IMAGE

When writing a Java applet, your code is overriding one of the standard applet methods, and you are not allowed to throw any exceptions that it would not. So, in general, you must handle exceptions.
What to do: The standard trick of writing a message to System.out works fine for debugging when running with the applet viewer. It also works fine with the Netscape browser for errors that you don't really expect to happen in working code (like your code had a null pointer) because Netscape provides a "Java console" under the Options menu that displays all messages.
However, for errors that you really want to bring to the attention of the user, such as they typed in their URL incorrectly and the network methods returned a "malformedURLException", you can put up a pop-up window in the style of professional GUI programs.
Note that you don't have to micromanage exceptions - you don't have to put a "try-catch" construct around every statement that can throw an exception. You can put the "try-catch" around the entire code with the same catch action or even put different catches for different actions of the errors.



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Tue Feb 18 1997