Sunday, 6 October 2019

Java Tutorials | Exception Handling in Java

What is an Exception?
An exception is an unwanted or unexpected event, which occurs during the compilation or execution of a program, that disrupts the normal flow of the program’s instructions.

Error vs Exception
Error: An Error indicates a serious problem that a reasonable application should not try to catch.
Exception: Exception indicates conditions that a reason the application might try to catch.

Exception Hierarchy
All exception and error types are subclasses of class Throwable which is the base class of the hierarchy. One branch is headed by Exception, is used for exceptional conditions that programs should catch. NullPointerException is an example of such an exception.

Another branch, Error is used by the Java run-time system(JVM) to indicate errors having to do with the run-time environment itself(JRE). StackOverflowError is an example of such an error. Errors cannot handle in Java. See the detailed hierarchy below.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...