import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.PrintWriter;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;

/**
 * Creates an exception class with the specified name suffixed by Exception.
 * This name is given as a command line argument.
 *
 * @version     1.4    May 1, 2000
 * @author      Franck van Breugel
 */
public class ExceptionCreator 
{
    /** Name of the author of the created exception class */
    private static final String AUTHOR = "Franck van Breugel";

    /** 
     * Creates an exception class with the specified name suffixed by 
     * Exception. This name is given as a command line argument.
     */
    public static void main(String[] args) 
    {   
        if (args.length > 0) 
        {   
            String name = args[0] + "Exception";
            try 
            {   
                PrintWriter handle = new PrintWriter(new FileOutputStream(name + ".java")); 

                SimpleDateFormat formatter = new SimpleDateFormat ("MMMM d, yyyy");
                Date today = new Date();

                handle.println("/**");
                handle.println(" * ");
                handle.println(" * ");
                handle.println(" * @version     1.1   " + formatter.format(today));
                handle.println(" * @author      " + AUTHOR);
                handle.println(" */");
                handle.println("public class " + name + " extends RuntimeException");
                handle.println("{");
                handle.println("    /** ");
                handle.println("     * Constructs a " + name + " without error message.");
                handle.println("     */");
                handle.println("    public " + name + "()");
                handle.println("    {");
                handle.println("        super();");
                handle.println("    }");
                handle.println();
                handle.println("    /** ");
                handle.println("     * Constructs a " + name + " with the specified error message.");
                handle.println("     * @param errorMessage Error message.");
                handle.println("     */");
                handle.println("    public " + name + "(String errorMessage)");
                handle.println("    {");
                handle.println("        super(errorMessage);");
                handle.println("    }");
                handle.println("}");
                handle.close(); 
            } 
            catch (FileNotFoundException e) 
            {   
                System.err.println("The file " + name + " exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.");
            }
        } 
        else 
        {   
            System.err.println("Provide the name of the exception class (without the Exception suffix) as a command line argument.");
        }
    }
}
