Showing posts with label Mobile App. Show all posts
Showing posts with label Mobile App. Show all posts

When is the code within a catch block executed?

When is the code within a catch block executed?




a. When the code in the try block doesn't compile
b. When the try block finishes executing
c. When a runtime error occurs
d. When the exception specified in the catch block is thrown in the try block


Answer: d. When the exception specified in the catch block is thrown in the try block

You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because

You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because




a. data validation code should only be used for situations that are truly exceptional
b. all of the above
c. you can more accurately determine the cause of an invalid entry
d. your code will run faster


Answer: d. your code will run faster

Exception in thread "main" java.util.InputMismatchException

Exception in thread "main" java.util.InputMismatchException

at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)
What is the order of method calls?

a. java.util.Scanner.throwFor calls java.util.Scanner.next calls java.util.Scanner.nextDouble calls FutureValueApp.main
b. FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor
c. you can't tell from the information given


Answer: b. FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor

Exception in thread "main" java.util.InputMismatchException

Exception in thread "main" java.util.InputMismatchException

at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)
Which statement would you look at to find the source of the problem?



a. line 818 in the Scanner class
b. line 2324 in the Scanner class
c. line 17 in the FutureValueApp class
d. line 1420 in the Scanner class


Answer: c. line 17 in the FutureValueApp class

Exception in thread "main" java.util.InputMismatchException

Exception in thread "main" java.util.InputMismatchException

at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)
What caused the exception to occur?



a. You can't tell from the information given.
b. The user didn't enter the type of data the program was expecting.
c. The program couldn't format the double value that the user entered.


Answer: b. The user didn't enter the type of data the program was expecting.

Exception in thread "main" java.util.InputMismatchException

Exception in thread "main" java.util.InputMismatchException

at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)
What is this output called?



a. a method log
b. a stack trace
c. an exception handler
d. an exception hierarchy


Answer: b. a stack trace

You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because

You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because


a. all of the above
b. data validation code should only be used for situations that are truly exceptional
c. your code will run faster
d. you can more accurately determine the cause of an invalid entry


Answer: c. your code will run faster

When is the code within a catch block executed?

When is the code within a catch block executed?




a. When the exception specified in the catch block is thrown in the try block
b. When the try block finishes executing
c. When the code in the try block doesn't compile
d. When a runtime error occurs


Answer: a. When the exception specified in the catch block is thrown in the try block