11 - Exceptions Flashcards
Errors and exceptions are objects that …
represent unusual or invalid processing.
Error represents an …
unrecoverable situation and should not be caught.
Three ways to deal with exceptions.
- not handle the exception at all
- handle the exception where it occurs,
- handle the exception at another point in the program.
call stack trace
The messages printed when an exception is thrown provides a method call stack trace.
try-catch statement
A try-catch statement identifies a block of statements that may thrown an exception.
- each catch clause is called an exception handler
- finally clause is executed wither the try block is exited normally or because of a thrown exception.
If an exception is not caught and handled it?
it is propagated to the calling method.
A new exception is defined by deriving a…
new class from the Exception class or one of its decedents.
Checked exceptions must either …
be caught by a method or must be listed in the throws clause of any method that may throw or propagate it.
throws
throws clause is appended to the header of a method definition to formally acknowledge that the method will throw or propagate a particular exception if it occurs.
Unchecked exception requires …
throws clause
The only unchecked exceptions in Java are
objects of type RuntimeException or any of its decendents.
A stream is…
a sequential sequence of bytes; it can be used as a source of input or a destination for output.
Three public reference variables in the System class represent the standard I/O streams.
- System.in = standard input stream
- System.out = standard output stream.
- System.err = standard error stream (output for error messages)