Sample Code Sample Code: Exceptions


public class MyException extends VException {

    // Resource class for Exceptions.properties.
    private static final String RESOURCECLASS =
        "com.mycompany.myproduct.mytool.resources.Exceptions";

    ...

    /**
     * Protected methods to return the base name of the resource
     * bundle property file.
     */
    protected String getBundleName() {
        return RESOURCECLASS;
    }

    /**
     * Protected method to return the ClassLoader for this class.
     */
    protected ClassLoader getResourceClassLoader() {
        try {
            return this.getClass().getClassLoader();
        } catch (Exception e) {
            return ClassLoader.getSystemClassLoader();
        }
    }
}
...

try {
    if (some error)
        throw new MyException("errorKey");
} catch (Exception e) {
    System.out.println("Error doing something.  Exception msg is "
        + e.getLocalizedMessage();
}