Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Module 9 Mastery Check

wolvesled edited this page Sep 5, 2013 · 1 revision
  1. What class is at the top of the exception hierarchy? Answer: Throwable
  2. Briefly explain how to use try and catch. Answer: use try { } block to enclose the code that may generate exception, and followed with one or more catch (exception e) { } block for each specific exception that to handle.
  3. What is wrong with this fragment? // ... vals[18] = 10; catch (ArrayIndexOutObBoundsException exc) { // handle error } Answer: testing code must be enclosed in a try block.
  4. What happens if an exception is not caught? Answer: it will eventually caught by JVM and terminate the program.
  5. What is wrong with this fragment? class A extends Exception { ... class B extends A { ... // ... try { // ... } catch (A exc) { ... } catch (B exc) { ... } Answer: making the catch of superclass exception before catch of subclass exception will make the subclass exception catch block unreachable, which generates an error.
  6. Can an exception caught by an inner catch rethrow that exception to an outer catch? Answer: Yes, but only to the enclosing outer catch.
  7. The finally block is the last bit of code executed before your program ends. True of False? Answer: False, it is the code executed after a try/catch block either exception is caught or not.
  8. What type of exceptions must be explicitly declared in a throws clause of a method? Answer: those checked exceptions.
  9. What is wrong with this fragment? class MyClass { // ... } // ... throw new MyClass(); Answer: MyClass is not inherit from Throwable, cannot be throw like an exception.
  10. In question of the Mastery Check in Module 6, you create a Stack class. Add custom exceptions to your class that report stack full and stack empty conditions.
  11. What are the three ways that an exception can be generated? Answer: exception can be generated by an error in JVM, or from the program, also can be manually generated.
  12. What are the two direct subclasses of Throwable? Answer: Exception and Error

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.