What is Exception and Runtime stack mechanism?
- An unexpected unwanted even that disturbs normal flow of the program is called an exception.Â
- It is highly recommended to handle the exceptions and the main objective of exception handling is graceful termination of the program.
- Exception Handling doesn’t mean repairing an exception. We have to provide an alternative way to continue rest of the program normally is the concept of Exception handling.
- For example, our programming requirement is to read the data from remote file locating. At runtime, if the file is not available our program should not be terminated abnormally. We have to provide some local file to continue rest of the program normally.
- This way of defining alternative is nothing but exception handling.
- The core advantage of exception handling isÂ to maintain the normal flow of the application. An exception normally disrupts the normal flow of the application that is why we use exception handling.
- Exceptions are used to indicate many different types of error conditions.
- JVM Errors:-Â OutOfMemoryError, StackOverflowError, LinkageError.
- System errors:- IOException, SocketTimeoutException,Â FileNotFoundException.
- Programming errors:-NullPointerException,Â ArrayIndexOutOfBoundsException, ArithmeticException
Exception handling keyword summery
- Try:- to maintain risky code.
- Catch:- to maintain exception handling code
- Finally:- to maintain cleanup code
- Throw:- to handover our created exception object to JVM manually.
- Throws:- to delegate the responsibility of creating exception handling to the caller.