when i search this on google then it show that error means compile time error and exception is runtime error? but i think that it is not that so....
That is generally correct. Although the terms are colloquially interchangeable in many domains.
An Error
, also known as a compile-time error, is a statement of fact. (Or NOT fact) The compiler is unable to compile the output.
An Exception
is raised at runtime and is the result of an exceptional combination of values.
Because an
Exception
is raised at runtime, we can generally write code to catch and handle or workaround an exception within your script or code. AnError
prevents the code from being compiled and thus executed at all, so our only option is to modify the code to resolve anError
.
A compiler may perform syntax and sometimes type checking to ensure that the code follows a set of pre-determined rules and can be compiled into executable statements, but it is not until invalid values are passed into those statements that an Exception can occur, that is harder for a compiler to do and so is generally only detected at Runtime.
Some advanced or specialised compilers may perform checks against common values and as a programer you can write unit tests to try and pre-emptively detect exceptions before releasing your code.