RUVIDEO
Поделитесь видео 🙏

exception handling in python | error handling in python смотреть онлайн

In this video you will learn about error handling or exception handling in python.

Exception handling python
In a python program we can face following two types of errors:
1. Syntax Error : Such errors which occurs due to wrong program syntax, are called as Syntax Error. Consider the following example:
print("Hello"))
The above code will give Syntax Error

2. Runtime Error or Exception : When our program is syntactically correct but terminates the execution due to abnormal situation, then such condition or error is called runtime error or exception. Consider the following example:
print(x)
The above code is syntactically correct but produces NameError as x is not assigned earlier.

Error Handling or Exception handling
The exception/error handling is the mechanism which prevent our program from abnormal termination in case an exception is generated. In python the exception handling is built around the following keywords:
a) try : The try keyword is used to create a block that contains the statements which can generate an exception. When exception is occurred inside the try block, the control is transferred to the except block, statements after that place are not executed inside try, and except block runs.

Syntax
try:
statements






b) except : The except block is used to contain the statements which are executed when exception occurs in try block. Generally we use exception name with except block. We can have multiple except block with a try to handle different type of exceptions. It is also possible to create except block without exception name. Such except block can handle any type of exception.

Syntax:
try:
statements
except ExceptionName:
statements

c) else : We can also use the else block after the except block. The else block is only executed when no exception is raised inside the try block.

Syntax:
try:
statements
except ExceptionName:
statements
else:
statements







d) finally : The finally keyword is used to create a block that is always executed whether exception occur or not. Generally it is used to closing the db connection or to close opened files etc. It appears after else/except block. If try does not have except then finally can appear immediately after the try block.
Syntax:
try:
statements
except ExceptionName:
statements
else:
statements
finally:
statements


e) raise : It is used to manually generate and throw an error.
Synatx:
raise Exception(message)








Consider the following example with try except:
a=int(input("Enter the first number : "))
b=int(input("Enter the second number : "))
c=a/b #generates exception ( ZeroDivisionError ) if b is 0, and rest of code is not executed
print(a, "/",b, "=",c)
print("Program completed")

We can handle this situation using the following program:
try:
a=int(input("Enter the first number : "))
b=int(input("Enter the second number : "))
c=a/b #generates exception ( ZeroDivisionError ) if b is 0, and rest of code is not executed
print(a, "/",b, "=",c)
except ZeroDivisionError:
print("Do not divide an integer by zero")
else:
print("No exception raised")
finally:
print("Program completed")
Note: in the above program if b is 0 then exception is generated and control goes to except and then finally block. Else block is skipped. If b is not zero then try completes successfully then else and then finally is executed.

The following example demonstrates the raise keyword:
try:
salary=int(input("Enter the salary : "))
if salary == 0:
raise Exception("Salary must not be zero")
print("Salary is ",salary)
finally:
print("Program completed")




#python_by_tarun_sir #tarun_sir #python #tarun_sir_python #python_video_61 #error_handling_in_python #python_tutorial #exception_handling_in_python

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «exception handling in python | error handling in python» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.