November 10, 1998

Function Try Blocks

A function try block is a function whose body consists of a try block with its associated handlers (catch-statements). A function try block is probably most often used in a class constructor. It enables you to catch exceptions that might be thrown by a base class constructor, or by a

Exception Specifications are Checked at Run Time

A function can specify explicitly what type of exception it may throw. An exception specification, however, is not checked at compile time, but rather at run time: class X {};int f(); // no exception specification, can throw any type of exceptionvoid g(int j) throw(); // promises not to throw any

Square Buttons in the JToolBar

When placing JButtons in the JToolBar, use gif icons that are 25 x 25 pixels. Then create a ToolButton class that sets the insets to zero so that the buttons are square instead of rectangular: public class ToolButton extends JButton { public kmfToolButton(Icon img) { super(img); setMargin(new Insets(0,0,0,0)); }

Alternative Java Coding Environment

For quick Java development, consider using MicroEdge’s Visual SlickEdit ( instead of an IDE. It recognizes and highlights Java keywords and inserts braces and indents code correctly. To make it compile for you when you press the Compile tool button, just set Project|Properties – Tools Compile to javac -deprecation

Alpha to Integer Conversion

C and C++ programmers are accustomed to using the atoi() function to convert strings to numeric integer values. Although Java doesn’t have an atoi() method, it provides the same capability by way of the more obscure static parseInt() method of the Integer class. This code was tested using JDK1.1.6 under