CMIS 242 Intermediate Programming homework 3

profilekrken35
 

 

  1. What RuntimeException, if any, will the following program throw?

    class Exception1
    {
        public static void main(String[] args)
        {
            int x = 1/0;
        }
    }
  2. How can you tell whether an exception is checked or unchecked? What is required of checked exceptions that is not required of those that are unchecked?

  3. What is the output of the following program?
    class Exception2
    {
        public static void main(String[] args)
        {
            try
            {
                aMethod();
                System.out.println("After the call");
            }
            catch (ArithmeticException exception)
            {
                System.out.println("Arithmetic Exception");
            }
            catch (RuntimeException exception)
            {
                System.out.println("Runtime Exception");
            }
            System.out.println("After the try-catch statement");
        }
        private static void aMethod() throws RuntimeException
        {
            int x = 1/0;
        }
    }

    What will happen if the order of the catch blocks is reversed?

  4. Why won't the following program compile?

    class Exception3
    {
        public static void main(String[] args)
        {
            if (Integer.parseInt(args[0]) == 0)
                throw new Exception("Invalid Command Line Argument");
        }
    }

    Correct it so it will compile.

  5. Explain the difference between the keywords throw and throws. When is each used?
    • 10 years ago
    • 3
    Answer(1)

    Purchase the answer to view it

    blurred-text
    • attachment
      cmis_242_intermediate_programming_homework_3_solution.docx
    Bids(0)