Exceptions Flashcards
What are the only two subclasses of java.lang.Throwable?
java.lang.Error and java.lang.Exception
What can be the type of a catch argument?
Any class that is-a Throwable.
What happens if you call System.exit(…)
The JVM stops executing.
If this is in catch block, no further code will run, including a finally statement.
What class of objects can be declared by the throws clause?
Exception, RuntimeException, and Error.
What must a try statement always have?
catch, finally or both
Will a stack trace be printed for the following code?
System.out.println(exception);
No.
Only the name of the exception class and its message will be printed.
What happens when you use exception.printStackTrace( )
A complete chain of the names and methods is called, along with line numbers.
What is java.lang.SecurityException?
It is thrown by the security manager upon security violation.
What is java.lang.ClassCastException?
It is thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.
example:
Object x = new Integer(0); System.out.println((String)x)
What is NullPointerException a subclass of?
RuntimeException
What is the parent class of IOException
Exception
What is the length of args if no argument is passed in for the following main method declaration?
public static void main (String[]args) { }
The length is zero.
It is never null.