Python Tutorial for Beginners 38 - Raising Exceptions In Python

preview_player
Показать описание
In this Python Tutorial for Beginners video I am going to show How to Raise Exceptions in Python.The raise statement allows the programmer to force a specified exception to occur.To Raise an exception, a raise-statement is used to throw a value.When an exception is thrown, the try block stops executing and the Except-block begins execution. This is catching or handling the exception.
First we define classes of exceptions which may be thrown. Upon expected situation, we will throw an exception. we Use the raise statement to generate exceptions.

#PythonTutorialforBeginners #ProgrammingKnowledge #LearnPython #PythonCourse
★★★Top Online Courses From ProgrammingKnowledge ★★★

★★★ Online Courses to learn ★★★

★★★ Follow ★★★

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

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
Рекомендации по теме
Комментарии
Автор

your are not human...how you know every Programming language ....But thanks for your tutorials and keep making it

mohdrizwan
Автор

Why throw an exception in first place? I know it sounds stupid but
Im learning py and i find it very unreasonable . could you plz explain

Alicer
Автор

I'm WaitingFor your Networking Hope you upload Fast

AJShadowVideos
Автор

self.sth but you wrote self.__sth.have you a video that explained it?

oddnumber
Автор

hey, can you help me makeing a spatial database in SQlite for my class?

simon.
Автор

Hi Programmingknowledge

I have a question for python
I don't how to do my homework

my homework is - write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10 and 4 and match the output below.

Invalid input
Maximum is 10
Minimum is 2

This is my work

largest = None

smallest = None



while True:

num = input ('Enter a number')

if num == 'done' : break

try:

  number = float(num)

except:

  print('Invalid input')

 

for value in (number):

if largest is None :

  largest = value

elif float(value) < float(largest):

  largest = value

print('Maximum is', largest)



for value in (number):

if smallest is None:

  smallest = value

elif float(value) > float(smallest):

  smallest = value

print('Minimun is', smallest)


but the output is not

Invalid input

Maximum is 10

Minimum is 2


I want to know where is wrong
Please help me

isaaclee