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....
-
1Error is a situation which cannot be fixed and can be reported only. Exception is not an error, this is special situation which must be handled. – Akina Feb 02 '22 at 05:23
-
This concept of Error vs Exception is not specific to databases, it it one of the fundamental paradigms of writing code, either the code can be interpreted or it is an `Error`, interpreted or _compiled_ code can raise `Exceptions` at runtime. In MySQL (and other RDBMS) there is a _type_ of Exception called an `Error Exception` and that just further confuses the terminology... – Chris Schaller Feb 02 '22 at 05:30
-
https://dev.mysql.com/doc/connector-python/en/connector-python-api-errors-error.html#:~:text=Initializing%20the%20exception%20supports%20a%20few%20optional%20arguments%2C,used%20by%20%20your%20application%20to%20raise%20exceptions. – Chris Schaller Feb 02 '22 at 05:31
-
1"_If a condition is raised that causes a statement to have no effect other than that associated with raising the condition (that is, not a completion condition), then the condition is said to be an exception condition or exception. If a condition is raised that permits a statement to have an effect other than that associated with raising the condition (corresponding to an SQLSTATE class code of successful completion, warning, or no data), then the condition is said to be a completion condition._" ISO/ANSI SQL standard. I.e. an error is an exception. – jarlh Feb 02 '22 at 07:55
1 Answers
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.
- Technically an error is a state in code that has raised an exception in the compiler's runtime :)
An Exception is raised at runtime and is the result of an exceptional combination of values.
Because an
Exceptionis raised at runtime, we can generally write code to catch and handle or workaround an exception within your script or code. AnErrorprevents 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.
- 10,266
- 3
- 41
- 71