- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Are Python Exceptions runtime errors?
All python exceptions are not runtime errors, some are syntax errors as well.
If you run the given code, you get the following output.
File "C:/Users/TutorialsPoint1/~.py", line 4 else: ^ SyntaxError: invalid syntax
We see that it is syntax error and not a runtime error.
Errors or inaccuracies in a program are often called as bugs. The process of finding and removing errors is called debugging. Errors can be categorized into three major groups:
- Syntax errors 2. Runtime errors and 3. Logical errors
Python will find these kinds of errors when it tries to parse your program, and exit with an error message without running anything. Syntax errors are like spelling or grammar mistakes in a language like English.
If a program is free of syntax errors, it will be run by the Python interpreter. However, the program may exit if it encounters a runtime error – a problem that went undetected when the program was parsed, but is only revealed when the code is executed.
Some examples of Python Runtime errors −
- division by zero
- performing an operation on incompatible types
- using an identifier which has not been defined
- accessing a list element, dictionary value or object attribute which doesn’t exist
- trying to access a file which doesn’t exist
- Related Articles
- Examples of runtime errors in Python?
- Difference between Compile Time Errors and Runtime Errors in C Program
- What is the base class for errors and exceptions in Java?
- Concrete Exceptions in Python
- Why are Python exceptions named "Error" (e.g. ZeroDivisionError, NameError, TypeError)?
- Database Handling Errors in Python
- What are common programming errors or 'gotchas' in Python?
- Raising an Exceptions in Python
- User-Defined Exceptions in Python
- What are checked exceptions in Java?
- What are unchecked exceptions in Java?
- What are custom exceptions in Java?
- What are chained exceptions in Java?