15. Exceptions Flashcards

1
Q

What information is contained in an Exception object?

A

It contains information about the error, stored in its instance variables. In particular it includes a stack trace containing the source line number, method name and class name at which the error occurred.

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

What is the difference between the following?

  1. public Exception() { }
  2. public Exception(String m) { }
A

One creates an exception that has no message associated with it. The second one however takes a String which is to be used as the message.

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

When does an Exception have a cause?

A

When there is another exception that caused this exception to be created.

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

What does getMessage() method return?

A

Describes the reason for a given error/exception.

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

Name five types of exception.

A

ArrayIndexOutOfBoundsException, IllegalArgumentsException, NumberFormatException, ArithmeticException, NullPointerException

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

What is the cause of an exception?

A

It displays what caused the current Exception.

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

Where do we use javadoc: throws tag? (tag throwing)

A

When writing document comments, we use this tag to describe the exceptions that a method throws.

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

How do we specify the kind of exceptions a method might throw?

A

By writing “throws TypeOfException” behind the method.

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

What is different about RuntimeException, compared with other kinds?

A

Usually other kinds of exceptions that can be thrown by a method, either directly by a throw statement or indirectly via another method, must be caught by the method or it must say in its throws clause that it throws the exception. However for RunetimeExceptions we do not have to throw or catch anything.

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

What is the difference between standard error and standard output?

A

ss

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

What kind of Java item is System.err? (E.g is it an instance variable?)

A

ss

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

What class features does the Character class provide?

A

ss

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

What parts does a try statement have?

A

ss

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

What happens if two catch clauses match an exception?

A

ss

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

Where does control transfer to when the throw statement is executed?

A

ss

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