How To Handle THESE Errors!! #python #programming #coding

preview_player
Показать описание
This short video explains how to use try except statements to handle errors in Python.

Background Music:
Attribution 4.0 International (CC BY 4.0)
Рекомендации по теме
Комментарии
Автор

I thought you were gonna input a string 😂

pinetree
Автор

while True:
n = input("numerator")
try:
n = int(n)
# do your video thing…
break
except ValueError:
print("input numbers please")

LorencCala
Автор

User is either a good guy or monster that make engineer cry everytime they find a way to break the entire thing

AnotherRandomCreator
Автор

Why use the else statement instead of printing the answer in the try statement?

AsTheStarsFallDown
Автор

It gets way weirder. Error handling is the crux of programming

TheSkepticSkwerl
Автор

Please do more of these shorts !!! I LOVE THEM 🔥🔥🔥❤️❤️❤️

Iಠ_ಠl
Автор

I feel like python puts ‘else’ everywhere even tho it doesn’t make any sense

jakob
Автор

In the JavaScript, we are using: Try, Catch, Finally.

For example:
We have a code that you think will have an error.
(Notice: async code always do in the try-catch.)

Try{
//Simple code
}Catch(error){
Console.log(error);
//Notice: never place error in console. Show it to a person using your site.
} Finally {
Console.log("Lmao To be honest, I don't care about the mistake".
}

Ok now let's understand what does they do?
Try : Here we check the code.
Catch :There is nothing but catching and showing errors.
Finally : Does he really care if there is a mistake or not? In the end it will still be.

I think I explained well! I'm still a Junior, so I'm still learning, and will soon switch to React.js!

BehaplayerYT
Автор

We all have been there, thinking how tf am I gonna stop some user to input string on numeric only function.

joezachary
Автор

This isn't the best case for a try-except, you can just put a check if the second number == 0

bettercalldelta
Автор

This is the perfect villain story for the bare except cult leader

matthewlui
Автор

Use
Dinominator -1 +1 method meaning if it can't -1 than it's not number solved

CC-.
Автор

I’m so glad I looked at this paused it and fixed it in my head with the value error im not diminish eith zerodivision error but now I am cool vid Ty

JoseTorres-zvbx
Автор

you could use if statement instade

like if not isinstance(n, (int, floa)) or not isinstance(d, (int, float)): print("%s %s is not allowed use into or float only." % ( type(n), type(d) )

gamingland
Автор

some times handling an error case is faster in python than using an if else statement.

jratnerd
Автор

I handle ALL my errors! This is why, when I implement my function in an hour, I spent next 10 covering all edge cases for errors 😂

bankaihampter
Автор

Why not just use an if statement that checks if the denominator is set to 0?

mememan
Автор

Input validation is required to make it bullet proof. Just did that on my basic calculator 😅😅

abzaman
Автор

I feel like an assert statement is clever for these kinds of situations

AlphaHenriksen
Автор

I had no idea about the else block here 😮 Thank you!

Question. What is the difference in using an else block and going with what I usually do, which is to just write code after the except block, assuming all unhandled exceptions will be raised and stop execution anyway?

Is it because the code in that else block will run only iff there were no raised exceptions, whether handled or not? If so, that's awesome. It took some thought, but I think I have always used a bool for that scenario.

Again, thanks!

Sorry for the book. It wasn't intentional 😅

CttageChees