Errors Can Be of Various Types
Errors Can Be of Various Types
Compile time errors: syntax errors and static semantic errors indicated by the compiler.
Runtime errors: dynamic semantic errors, and logical errors, that cannot be detected by the compiler
(debugging).
Syntax Error
Syntax errors often called as parsing errors, are predominantly caused when the parser detects a syntactic issue
in your code.
Semantic Errors
Semantic errors are improper uses of “program statements”, we are saying here that logic errors produce
wrong data while semantic errors produce nothing meaningful at all.
What is an Exception?
An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the
program's instructions. In general, when a Python script encounters a situation that it cannot cope with, it raises
an exception. An exception is a Python object that represents an error.
Many a time, there are valid as well as invalid exceptions. Exceptions are convenient in many ways for handling
errors and special conditions in a program. When you think that you have a code which can produce an error,
you can use exception handling technique.
Error handling increases the robustness of your code, which guards against potential failures that would cause
your program to exit in an uncontrolled fashion.
Some of the common built-in exceptions in Python programming along with the error that cause them are listed
below:
KeyboardInterrupt Raised when the user hits the interrupt key (Ctrl+C or Delete).
RuntimeError Raised when an error does not fall under any other category.
UnicodeTranslateErro
Raised when a Unicode-related error occurs during translating.
r
You can raise an exception in your program by using the raise exception statement. Raising an exception breaks
current code execution and returns the exception back until it is handled.