Week 3 - Intermediate Java - Handling Problems, Exceptions and Errors, Collections Flashcards
Describe the difference between exceptions and errors in Java.
In the java compilation process, the compiler checks that any checked exceptions that could be thrown are handled. If this is not the case, the compiler cannot compile the code. This is an example of a compilation error - not an exception.
Exceptions are never thrown during the compilation process - they can only be thrown when the code is executing (running). Compilation errors generally occur due to improper syntax, like calling a method that doesn’t exist, forgetting a semicolon on a line, using the wrong data type, using a reserved keyword incorrectly, and as we’ve shown, not handling checked exceptions properly.
Exceptions are never …..
thrown during the compilation process - they can only be thrown when the code is executing (running).
Compilation errors generally occur due to….(4)
improper syntax,
like calling a method that doesn’t exist,
forgetting a semicolon on a line,
using the wrong data type, using a reserved keyword incorrectly,
and as we’ve shown, not handling checked exceptions properly.
The exception class hierarchy starts with the….
Throwable class which inherits from Object.
The Exception and Error classes both extend
Throwable class
An Error represents something that…
went so horribly wrong with your application that you should not attempt to recover from
When the source code fails before it finishes compiling, this is known as a…?
Compilation error
What class is a general class which provides an abstraction for all exceptions?
Exception
Exceptions that require mandatory handling are called
checked exceptions, The compiler will check that such exceptions are handled by the program.
The _____ class represents all possible objects that can be thrown by a throw statement and caught by a catch clause in a try..catch statement.
Throwable
Subclasses of the class Exception which are not subclasses of ______ are checked exceptions.
RuntimeException
If an error is predictable but unpreventable and reasonable to recover from, a checked exception should be used
True
Since Java has exception-handling capability, programmers do not need to write code to handle exceptions.
False
Exception handling can be done in one of two ways:
The first way is to place the statement in a try statement that has a catch clause that handles the exception.
The second way is to declare that the subroutine can throw the exception. This is done by adding a “throws” clause to the subroutine heading, which alerts any callers to the possibility that the exception might be generated when the subroutine is executed. The caller will, in turn, be forced either to handle the exception in a try statement or to declare the exception in a throws clause in its own header.
Exception-handling is mandatory for…
any exception class that is not a subclass of either Error or RuntimeException.
When risky code is written that has the possibility of throwing an exception, it can be dealt with in one of two ways:
Handling means that the risky code is placed inside a try/catch block
Declaring means that the type of exception to be thrown is listed in the method signature with the throws keyword. This is also called “ducking” the exception - you let the code which calls the method deal with it.
If the exception is not handled anywhere in the program, it will propagate up through the
call stack until it is handled by the JVM which then terminates the program.
When an exceptional condition occurs in the course of a Java program, a special class called an Exception can be thrown,…
which indicates that something went wrong during the execution of the program.
If an exception is NOT handled anywhere in the program, what will occur?
The exception propagates up through the call stack until it is handled by the JVM which will then terminate the program.
Exception handling is done via…?
A try-catch block
“Ducking” or declaring an exception is done with which keyword?
throws
Code that executes at the end of a try-catch block is designated with which keyword?
finally
When risky code is written that has the possibility of throwing an exception, it can be dealt with in one of two ways:
Handling means that the risky code is placed inside a try/catch block
Declaring means that the type of exception to be thrown is listed in the method signature with the throws keyword. This is also called “ducking” the exception - you let the code which calls the method deal with it.
What is troubleshooting?
Troubleshooting is a process that helps people identify issues or problems occurring in a system.