Java Exception Handeling & Java
Object Oriented Concepts Explained
e. Exception handling
An exception is an event that occurs during the execution
of a program that disrupts the normal flow of instructions.
Advantages of exception handling:
- It is separates error handling code from "regular"
- Propagating errors up the call stack (without tedious
- Grouping error types and error differentiation
Categories of exceptions:
1. Checked exceptions: A checked exception is an exception
that is typically a user error or a problem that cannot
be foreseen by the programmer. These are usually invalid
conditions in area, which is not in reach of programmer.
These exceptions cannot simply be ignored at the time of
compilation. Some examples are missing files or database
2. Runtime exceptions: A runtime exception is the programmer
could have avoided an exception that occurs that probably.
These reflect errors in programming logic.
3. Errors: These are not exceptions at all, but problems
that arise beyond the control of the user or the programmer.
Errors are typically ignored in your code because you can
rarely do anything about an error. For example, if a stack
overflow occurs, an error will arise. They are also ignored
at the time of compilation.
Java uses try and catch keywords for exception handling.
A try/catch block is placed around the code that might generate
an exception. Code within a try/catch block is referred
to as protected code, and the syntax for using try/catch
looks like the following: