Exception Handling Flashcards
What are compile time errors?
Errors that occur when you violate the rules of writing syntax are known as Compile-Time errors.
Most of the compile-time errors are due to typing mistakes.
The most common problems are:
Missing semicolons
Missing (or mismatch of) brackets in classes and
methods
Misspelling of identifiers and keywords Missing
double quotes in strings
Use of undeclared variables
Incompatible types in assignments, initializations.
Bad references to objects
Use of = in place of = = operator
What are runtime errors?
A runtime error in a program is an error that occurs while the program is running after being successfully compiled.
Runtime errors are commonly called referred to as “bugs” and are often found during the debugging process before the software is released.
The most common run-time errors are:
Dividing an integer by zero
Accessing an element that is out of the bounds of an array
Trying to store a value into an array of an incompatible class or type
Trying to cast an instance of a class to one of its subclasses
Passing a parameter that is not in a valid range or value for a
method
Trying to illegally change the state of a thread
Attempting to use a negative size for an array
Using a null object reference as a legitimate object reference to
access a method or a variable
Converting an invalid string to a number
Accessing a character that is out of bounds of a string
What Is an Exception?
An exception is an abnormal event that arises during the execution (run time) of the program and disrupts the normal flow of the program.
What is Java Error Class?
An Error is a subclass of Throwable that indicates serious problems.
Errors represent critical errors, once occurs the system is not
expected to recover from (irrecoverable).
Errors can be generated from mistake in program logic or
design.
Most applications should not try to handle it.
e.g. OutOfMemoryError, VirtualMachineError, AssertionError
What is Java Exception Class?
This class represents the exceptional conditions that user must handle or catch.
What are Checked Exceptions?
Checked Exception in Java is all those Exception which requires being catches and handled during compile time.
The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions
e.g.IOException, SQLException etc. Checked
What are Unchecked Exceptions?
Unchecked exceptions are usually caused by incorrect program code or logic such as invalid parameters passed to a method.
The classes that extend RuntimeException are known as unchecked exceptions.
Unchecked exceptions are checked at runtime.
e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException
What are Two ways to handle Exceptions?
Throw out and ignore
When an Exception occurs inside a code of the program simply
throw it out and ignore that an Exception occurs declare the
methods as throws Exception.
Catch and handle
If a code segment is generating an Exception place it inside a
try block. Then mention the way to handle the Exception
inside a catch block use try-catch block