What happens if method3 throws an exception what happens if


Chapter 12 Exception Handling and Text llo (although command line arguments are covered in chapter 7 of the book, they were not discussed in class until chapter 12)

1. What is the general format for a Try-Catch block?

2. Assume that amt1 and amt are integers which have some values in them. Write a try-catch block that will try to divide amtl by amt2 and put the result into a variable named quotient. If an ArithmeticException occurs, print a message saying "Invalid data" and set quotient to 0.

3. Assume that the main method has a try block that includes a statement which calls method

1. Inside method 1 is another try block that includes a statement which calls method

2. Inside method2 is another try block that includes a statement which calls method

3. What happens if method3 throws an exception? What happens if method2 has a catch block which can handle the exception? What happens if it does not have a catch block which can handle the exception? How does this progress if none of the methods can handle the exception (HINT: see page 460)

4. What are command line arguments and how can the program access them? Command line arguments are program variables which are supplied to the program at run time and these can be accessed by the parameters of the main function.

5. rite a program that will accept a list of strings as command line arguments. It wil step through these strings, convert each one to an integer and add them to a total. Finally, it will print the total.

Request for Solution File

Ask an Expert for Answer!!
Dissertation: What happens if method3 throws an exception what happens if
Reference No:- TGS02871209

Expected delivery within 24 Hours