Exceptions Flashcards

1
Q

What are the only two subclasses of java.lang.Throwable?

A

java.lang.Error and java.lang.Exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What can be the type of a catch argument?

A

Any class that is-a Throwable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens if you call System.exit(…)

A

The JVM stops executing.

If this is in catch block, no further code will run, including a finally statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What class of objects can be declared by the throws clause?

A

Exception, RuntimeException, and Error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What must a try statement always have?

A

catch, finally or both

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Will a stack trace be printed for the following code?

System.out.println(exception);

A

No.

Only the name of the exception class and its message will be printed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when you use exception.printStackTrace( )

A

A complete chain of the names and methods is called, along with line numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is java.lang.SecurityException?

A

It is thrown by the security manager upon security violation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is java.lang.ClassCastException?

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is NullPointerException a subclass of?

A

RuntimeException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the parent class of IOException

A

Exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the length of args if no argument is passed in for the following main method declaration?

public static void main (String[]args) { }

A

The length is zero.

It is never null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly