Python Tutorial for Beginners 37 - Try Except Else Finally (Python Exception handling)

preview_player
Показать описание
In this Python Tutorial for Beginners video I am going to show How to use Try Except Else Finally in Exception handling in Python.
else: statements executed if no exception
finally:clean-up statements always executed
A finally clause is always executed before leaving the try statement. A finally statements is guaranteed to be executed before leaving the try statement, whether an exception has occurred or not.
What are these exceptions? An exception is an event, which happens while the execution of a program, that disrupts the normal flow of the program. When some error error occurs an exception is raised. Python Exceptions are run-time errors. Exceptions are used to deal with extraordinary errors. Normally if we do not use Exception handling the execution of program stops as soon as exception is thrown.By default, the interpreter handles exceptions by stopping the program and printing an error message.

#PythonTutorialforBeginners #ProgrammingKnowledge #LearnPython #PythonCourse
-------------------Online Courses to learn----------------------------
----------------------Follow---------------------------------------------
-------------------------Stuff I use to make videos -------------------
Stuff I use to make videos
------------------Facebook Links ----------------------------------------

List of exception in Python
CLASSES
object
BaseException
Exception
ArithmeticError
FloatingPointError
OverflowError
ZeroDivisionError
AssertionError
AttributeError
BufferError
EOFError
ImportError
LookupError
IndexError
KeyError
MemoryError
NameError
UnboundLocalError
OSError
BlockingIOError
ChildProcessError
ConnectionError
BrokenPipeError
ConnectionAbortedError
ConnectionRefusedError
ConnectionResetError
FileExistsError
FileNotFoundError
InterruptedError
IsADirectoryError
NotADirectoryError
PermissionError
ProcessLookupError
TimeoutError
ReferenceError
RuntimeError
NotImplementedError
RecursionError
StopAsyncIteration
StopIteration
SyntaxError
IndentationError
TabError
SystemError
TypeError
ValueError
UnicodeError
UnicodeDecodeError
UnicodeEncodeError
UnicodeTranslateError
Warning
BytesWarning
DeprecationWarning
FutureWarning
ImportWarning
PendingDeprecationWarning
ResourceWarning
RuntimeWarning
SyntaxWarning
UnicodeWarning
UserWarning
GeneratorExit
KeyboardInterrupt
SystemExit
Рекомендации по теме
Комментарии
Автор

Please create a series on advanced programming !!! btw great work 👍

punitchoudhary
Автор

What is the use of finally? We can get "__finally__" printed outside of this try-except block also. Not able to understand the difference it will create

result = None
a = float(input('Number 1: '))
b = float(input('Number 2: '))

try:
result = a / b
except ZeroDivisionError as e:
print("ZeroDivisionError = ", type(e))
except TypeError as e:
print("TypeError = ", type(e))
else:
print('__else__')
finally:
print('__finally__')

print('Result = ', result)
print('End')

guptamols