Error and Exception
Error and Exception
1. Syntax errors
2. Logical errors
3. Syntax error
The syntax error occurs when we are not following the
proper structure or syntax of the language.
A syntax error is also known as a parsing error.
When Python analyse the program and finds an incorrect
statement it is known as a syntax error.
When the parser (during analyse) found a syntax error it
exits with an error message without running anything.
Incorrect indentation
Missing colon, comma, or brackets
Putting keywords in the wrong place.
EXAMPLE
Logical errors (Exception)
Raising Exception
The raise statement allows the programmer to force a specific exception
to occur. The sole argument in raise indicates the exception to be raised.
This must be either an exception instance or an exception class (a class
that derives from Exception).
ORI
f a condition does not meet our criteria but is correct according to the Python interpreter,
we can intentionally raise an exception using the raise keyword. We can use a
customized exception in conjunction with the statement.
EXAMPLE