exxxcepppppppption Flashcards
What does Exception and Error extend?
Class called Throwable
What is the sub class of Throwable?
Exception and Error
What is the sub class of Exception
RunTimeException
What are runtime exception? They are also known as?
unchecked exceptions.
Exceptions tend to be unexpected but not necessarily fatal
What is checked exception?
Checked exceptions tend to be more anticipated—for example, trying
to read a fi le that doesn’t exist.
java.lang.RuntimeException extends what?
java.lang.Exception
What is throw?
tells Java that you want to
throw an Exception
What is throws?
throws simply declares that the method might throw an Exception. It
also might not
What do you pass in a throw?
String parameter with message or can pass no parameters
throw new Exception();
throw new Exception(“Thing”);
What type of expection is NullPointerException
Run time exception
What exception does this produce?
~~~
String[] animals = new String[0];
System.out.println(animals[0]);
~~~
ArrayIndexOutOfBoundsException
What is error’s subclass of?
is the program required to declare or handle?
subclass of Error; No
What is checked exception sub class of?
is the program required to declare or handle?
Subclass of Exception but not subclass of RuntimeException.
Yes
What is run time exception sub class of?
is the program required to declare or handle?
Subclass of RuntimeException.
They don’t have to be handled or declared.
They can be thrown by the programmer or by the JVM
No.
3: void explore() {
4: try {
5: fall();
6: System.out.println(“never get here”);
7: } catch (RuntimeException e) {
8: getUp();
9: }
10: seeAnimals();
11: }
12: void fall() { throw new RuntimeException(); }
fall() calls new RuntimeException and goes directly to line 7
Does it compile?
try
fall();
catch (Exception e)
System.out.println(“get up”);
No because braces are missing.
Does it compile?
try {
fall();
}
No because catch is missing
catch is not
required if finally is present.
true
When is finally used?
finally is typically used to close resources such as fi les or databases
When does finally not get executed?
System.exit(0);.