Mostly an error or exception in java occurs due to programming error, client code error or due to resource failures in applications. In this tutorial, we are talking about the nature and types of exceptions in Java.
There are basically two types of errors , compile time and run-time.
The compile time error occurs, when the defined syntax of the program is wrong or somthing left incomplete. For example if your code missed the code terminater(;) or the sytax of writing method or class is wrong then in such cases your program can throw a compile time error.
A compile time error occurs at the time of compilation and it restrict program to be execute.
Where as a Run-time Error occurs at the time of executing code. The base class for Runtime exception class is java.lang.RuntimeException that contains several other methods to handle runtime exceptions. Few examples of Java run time exceptions are NullPointerException, SecurityException, SystemException, JMRuntimeException and WebServiceException etc.
A RunTime exception can occurs due to null pointer, out of bound array access or also in case if the file is not found.
See the image given below that explains the flow of exception hierarchy:
Posted on: October 2, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles