Exceptions in Python: Types of Errors in Python (Syntax, Logical) - Python Tutorial for Beginners

preview_player
Показать описание
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ Exceptions in Python: Types of Errors in Python (Syntax Errors, Logical Errors)

You can make certain mistakes while writing a program that lead to errors, when you try to run it. During its execution, Python program terminates as soon as it encounters an error, that is not handled. These errors can be classified into 2 classes:

- Syntax errors in Python
- Logical errors in Python - also known as Exceptions

○ Syntax Errors in Python

Errors caused by not following the proper structure of the language, are called syntax error - or parsing error. Syntax errors are the most basic type of error. They arise when the Python parser is unable to understand a line of code. Most syntax errors are: typos, incorrect indentation, or incorrect arguments. If you get this error, try looking at your code for any of these: misspelling, missing, or misusing keyword. An arrow indicates where the parser ran into the syntax error.

for action in ["like", "comment", "share"]
^
SyntaxError: invalid syntax

○ Logical Errors in Python (Exceptions)

Errors that occur at runtime - after passing the syntax test - are called Exceptions in Python, or Logical errors in Python. These errors are the most difficult type of errors to find because they will give unpredictable results and may crash your program.

A lot of different things can happen, if it encounters a Logical error. Whenever these types of runtime errors occur, Python will create an Exception object.

Exceptions arise when the python parser knows what to do with this piece of code, BUT is unable to perform this action. e.g Trying to access the Internet without internet connection: the Python interpreter knows what to do with that command, but is unable to perform it.

Illegal operations can raise Exceptions, too. Actually, there are plenty of built-in exceptions that are raised in Python, when the following corresponding errors occur: ValueError, TypeError, ZeroDivisionError, ImportError - and, so many more! Consequently, if not handled properly, Python prints the Traceback of that error. And the last line of this message indicates what type of exception error your program ran into - along with some details about what triggered this error.

for i in [1, 2, 3]:
print(i / 0)

Traceback (most recent call last):
File "stdin", line 2, in module
ZeroDivisionError: division by zero

Fortunately, you can catch and handle all these kind of exceptions, then also adapt your program so it does not crash. You can also define your own exceptions in Python, when required!

After seeing the differences between Syntax errors and Exceptions in Python, Let's move forward and discover multiple ways to RAISE, CATCH and HANDLE Exceptions in Python.

Let's play this video, stick around and watch until the end of this video! 👍🏻

- Digital Academy™ 🎓

***

☞ WATCH NEXT:

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡

♡ SUPPORT US ♡

***
Рекомендации по теме
Комментарии
Автор

What are ALL differences between Types of Error in Python? 🤔

DigitalAcademyOnline
Автор

Hey man! Found you on my recommended again! Your makin pretty cool videos man. Keep it up. Must be a lot of work! 😎👍🏻

themagicjockels
Автор

Heyyy! 2 Weeks ago, i made a text-adventure game in python. The hole program ran completely fine, but there was always the red text in the console: scr/12345 does not exist. Since i discovered the try-except block, such error are no problem anymore. And now, i know that there are more specific exceptions in Python. I can handle more specific errors. So, i can print at a SyntaxError: [ERROR] Invalid Syntax. And if other error pop up, they will be shown as well and this is very very powerful! THAAAANKS FOR THIS CONTEST!!! ♥️ ♥️♥️♥️♥️

alopmemes
Автор

Hey! Again a nice video and I understood everything!

nichtmehramix