Exception Handling in Python | Python Tutorial - Day #36

preview_player
Показать описание
Python is one of the most demanded programming languages in the job market. Surprisingly, it is equally easy to learn and master Python. This python tutorial for absolute beginners in Hindi series will focus on teaching you python concepts from the ground up.

python, C, C++, Java, JavaScript and Other Cheetsheets [++]:

►Learn in One Video[++]:

►Complete course [playlist]:

Follow Me On Social Media
Comment "#HarryBhai" if you read this 😉😉
Рекомендации по теме
Комментарии
Автор

This guy never ever did any paid course after teaching for this many years on YouTube.
Huge respect for Harry bhai♥️♥️

aishwaryaporwal
Автор

Few important things to note about try and exception method:
1. We can use else clause with exception handling.
try:
result = 100 / 2
except ZeroDivisionError:
print(f"Division Error")
else:
print("Result is", result)

2. Using the finally clause in exception handling
try:
result = 10 / 0
except ZeroDivisionError:
print("Division by zero!")
finally:
print("This block of code will always execute.")

3. Raising exceptions using raise
try:
raise ValueError("This is a custom error message.")
except ValueError as e:
print("An error occurred:", str(e))

FaceSenseAustralia
Автор

BY CHATGPT:

There are several types of errors that can occur in Python:

Syntax errors: These occur when the code is not written in a proper format, and the interpreter is unable to understand it. For example, if you forget to close a parentheses or forget to indent code properly, you will get a syntax error.

Name errors: These occur when you try to use a variable that has not been defined.

Type errors: These occur when you try to perform an operation on a value of the wrong type. For example, if you try to add a string and a number, you will get a type error.

Index errors: These occur when you try to access an element in a list or a string using an index that is out of bounds.

Value errors: These occur when a built-in function receives an argument of the right type, but an inappropriate value.

Attribute errors: These occur when you try to access an attribute of an object that does not exist.

Import errors: These occur when you try to import a module that does not exist or cannot be found.

Key errors: These occur when you try to access a dictionary with a key that does not exist.

File not found errors: These occur when you try to open a file that does not exist or cannot be found.

Indentation errors: These occur when the indentation of the code is not consistent, which can cause the interpreter to behave unexpectedly.

Zero division errors: These occur when you try to divide a number by zero, which is not allowed in Python.

Recursion errors: These occur when a function calls itself recursively, but the base case is not defined, causing the function to call itself indefinitely.

Memory errors: These occur when the program tries to use more memory than the computer has available.

Overflow errors: These occur when a calculation produces a result that is too large to be stored in the allocated memory.

Underflow errors: These occur when a calculation produces a result that is too small to be represented accurately in the allocated memory.

Assertion errors: These occur when an assert statement fails.

Not implemented errors: These occur when a method or function has not been implemented yet.

Runtime errors: These occur while the program is running and can be caused by a variety of factors, such as invalid input, missing resources, or other unforeseen circumstances.

Security errors: These occur when the program tries to perform an action that is not allowed due to security restrictions.

Timeout errors: These occur when a program takes too long to run and exceeds the allotted time limit.

Unbound local errors: These occur when you try to access a local variable before it has been defined.

Internal errors: These occur when the interpreter encounters an unexpected condition that it cannot handle.

External errors: These occur when the program interacts with an external resource (such as a database or a network connection) and something goes wrong.

It is also worth noting that Python allows you to define your own custom errors using the Exception class. This can be useful if you want to create specific error handling logic for your program.

dxdelvin
Автор

CodeWithHarry please add some quizes and practice sets also in the course as you always do. So that we can practice that concepts we learned. And also make some sort of project after 30 days so that we can gain some confidence. Hope it will help.

technologymad
Автор

🥳🥳🥳 nice concept, with this we can get error in the middle of code printed and check for further code's correctness after that also kind a substitute for commenting above code or doing pass 😀

reality
Автор

If you are trying to run a python program and there are chances of getting errors, then we can handle those errors using try-exception technique. We can use try keyword and can write your block of code inside the try with proper indentation and then, we have to use except keyword and then we can anything that we want to happen with the program exceution whenenver the error occurs. We can also specify the types of error with except keyword like index error, value error and can write the body that we want to excute upon error occuring.

khemchand
Автор

Error dikhane ka stylish way 😁😁😁😁😁😁😁😁
# My code

box=[]
while(True):
try:
num = int(input("Enter num:"))
for i in range(1, num):
print(i)

x=[2, 3, 4, 5]
print(x[num])
break
except IndexError :
print("IndexError")
box.append(IndexError)

except ValueError:
print("ValueError: input a number beta")
box.append(ValueError)


for xm in box:
print(xm)

rudra
Автор

Thank you so much sir for creating this video!

technikalproblem
Автор

I have Watched 30+ Concept of Try and except But The way of teaching of yours IS so op.

codewithbhavesh
Автор

hello sir, i have tried this one:
try:
tup1 = (1, 2, 3, 4, 5)
tup1.insert(2, 9)
print(tup1)
# list1 = list(tup1)
# list1.insert(2, 9)
# tup1 = tuple(list1)
# print(tup1)
except AttributeError :
print("No changes can be made in a tuple directly, Once they are created")



also this one:
try:
dict = {"name": "rayees", "age": 23, "roll.No.": "17e31a0333", "DOB":"23/07/1999"}
# print(dict["name"])
print(dict["adhaar"])
except KeyError:
print("This key do not exist in dict")


Thank you so much harry sir

mohdrayees
Автор

u never disappoint, , i always understand your teachings

Studypoint
Автор

Thanks for giving this series Harry bhi
Please start practice series in python

deepakkumar-bfcr
Автор

please resume ML with Python video series 😭😭 really really need that

punyamsingh
Автор

Proud to learn python with you Harry bhai

JoyBoy_
Автор

Present from Bangladesh Brother. After 6 days of busyness, I am back to this course... #Day36 Done

eashovon
Автор

#DAY36 COMPLETED
THANK YOU #CodeWithHarry

__ayu
Автор

#36 completed
Love code with Harry 3000❤️

bibeksamal
Автор

please make more detailed videos on exeption handling

avijitdey
Автор

x=input("enter:")
if(x.isnumeric()) :
if(not 5<int(x)<9) :
raise Exception(print("not desired input"))
elif(x!='quit') :
raise Exception(print("not desired input"))

vatsalsharma
Автор

present sir ji today Thank you sooo sooo sooo much sirji to teach us the valuable things for god bless you with the best best bestest always in your keep it up help us always like huge huge huge respect for

hemhnys