15. Exceptions Flashcards
What information is contained in an Exception object?
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.
What is the difference between the following?
- public Exception() { }
- public Exception(String m) { }
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.
When does an Exception have a cause?
When there is another exception that caused this exception to be created.
What does getMessage() method return?
Describes the reason for a given error/exception.
Name five types of exception.
ArrayIndexOutOfBoundsException, IllegalArgumentsException, NumberFormatException, ArithmeticException, NullPointerException
What is the cause of an exception?
It displays what caused the current Exception.
Where do we use javadoc: throws tag? (tag throwing)
When writing document comments, we use this tag to describe the exceptions that a method throws.
How do we specify the kind of exceptions a method might throw?
By writing “throws TypeOfException” behind the method.
What is different about RuntimeException, compared with other kinds?
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.
What is the difference between standard error and standard output?
ss
What kind of Java item is System.err? (E.g is it an instance variable?)
ss
What class features does the Character class provide?
ss
What parts does a try statement have?
ss
What happens if two catch clauses match an exception?
ss
Where does control transfer to when the throw statement is executed?
ss