/**********************************************************
* try/catch block
* with java exception, and a forced exception
**********************************************************/
public class Except0
{
    public static void main(String[ ] args)
    {
        double total = 0;
        int    count = 0;

        //---- Check for entry of at least 2 arguments (not using exception) ----------

        if (args.length != 2)                                   
        {
            System.out.println("Missing args - Re-enter with total and count");
            System.exit(0);
        }


        //---- Check to make sure values are correct (using exceptions) ---------------

        try {
            total =  Double.parseDouble(args[0]);           //convert Strings to numbers
            count =  Integer.parseInt(args[1]);             //either could result in a JVM exception 

            if (count <= 0)	 
                throw new Exception("count less than or equal to 0");      //force a user generated exception 

            System.out.println(total / count); 
        }
        catch (Exception e) 
        {
            System.out.println("Cannot compute average - " +  e );         // same as e.toString( ) 
        }
    }
}