Question 1
What class is at the top of the exception hierarchy?
Question 2
What are the two direct subclasses of throwable?
Question 3
What is wrong with this method declaration?
void methodB(){
throw new RuntimeException();
System.out.println("Exception thrown");
}
Question 4
What is wrong with the code fragment below? :
class MyClass { //....
}
//....
throw new MyClass();
Question 5
An inner catch can rethrow an exception to an outer catch
Question 6
We should typically catch Exceptions of type Error.
Question 7
Complete the following try catch block so that MyCustomException is caught and so does any type of exceptions:
try{
//....
}
catch([a] ex1){
}
catch([b] ex2){
}
Question 8
Complete the class declaration of custom exception called MyCustomException. Also complete declaration for the overloaded constructor so that it will accept a String parameter and pass it to the base class constructor :
class [a] [b] {
public [c] ( [d] parameter){
[e] (parameter);
}
}
Question 9
What is wrong with this fragment?
//.....
vals[18] = 10;
catch (ArrayIndexOutOfBoundsException exc){
//handle error
}
Question 10
What is wrong with this code fragment?
class A extends Exception {}
class B extends A {}
//....
try{ //...
}
catch (A exc ) { .... }
catch (B exc) {.... }
Question 11
What happens if an exception is not caught? Choose the answers for this question:
Question 12
What is wrong with this method declaration?
void methodA(){
throw new ClassNotFoundException();
}