Python Tutorial: Using Try/Except Blocks for Error Handling

  Рет қаралды 681,234

Corey Schafer

Corey Schafer

8 жыл бұрын

We've all run into errors and exceptions while writing Python programs. In this video, we will learn how we can handle exceptions in specific ways and also look at the control flow of a try/except/else/finally statement. Understanding how to properly handle errors will provide us with the tools to make better software in the future. Let's get started.
The code from this video can be found at:
github.com/CoreyMSchafer/code...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python

Пікірлер: 481
@paul8683
@paul8683 6 жыл бұрын
You sir are a gift to amateur programmers.
@WasiMaster
@WasiMaster 4 жыл бұрын
@Abishek Raju Utoobguy
@ciaocomestai2372
@ciaocomestai2372 2 жыл бұрын
@@xfire3778 how your programming status?
@ciaocomestai2372
@ciaocomestai2372 2 жыл бұрын
@@xfire3778 Wow, you learned a lot, gg
@REVIEWSGALATTA
@REVIEWSGALATTA 10 ай бұрын
Aiyoo namma mind Anga pogudhe 😂😂
@AGMS1234
@AGMS1234 9 ай бұрын
​@@REVIEWSGALATTAVanakkam nanbare
@AdamThao92
@AdamThao92 4 жыл бұрын
Better content here than most paid-training content.
@iman2020
@iman2020 4 жыл бұрын
Exactly
@isharadhanushka7643
@isharadhanushka7643 3 жыл бұрын
damn right
@sujithnair232
@sujithnair232 3 жыл бұрын
Totally Agree
@pengli1175
@pengli1175 3 жыл бұрын
Yep
@satyamvats5438
@satyamvats5438 3 жыл бұрын
Exactly. These people helps us to go further even if we are not affordable of paid courses 😊
@panicbydesign7315
@panicbydesign7315 7 жыл бұрын
I have been looking everywhere and just could not wrap my head around multiple exceptions. Your explanation is succinct and well demonstrated. THANK YOU! I will be going back and watching the rest of your tutorials.
@FeedFall8
@FeedFall8 5 жыл бұрын
i know right dude!
@ShivamSingh-bx5lg
@ShivamSingh-bx5lg 5 жыл бұрын
Did you get the job?
@mohammedalzamil7191
@mohammedalzamil7191 4 жыл бұрын
hey did u get better / continur with coding?
@twattusbobble9845
@twattusbobble9845 Жыл бұрын
I have just been battling all day with coding challenges in MIT intro to computer science for the error handling section. I've watched this video once and I now get it perfectly. You're really really good at explaining stuff!
@kimcato5326
@kimcato5326 5 жыл бұрын
I love your videos! They are very well explained and short... better than my professor's. I am writing better programs because of your videos. Your videos are a GOD send.
@Xaminn
@Xaminn 4 жыл бұрын
*Puts entire project inside a Try and Except block*
@narenmohan3426
@narenmohan3426 4 жыл бұрын
LOL XD
@kwan098
@kwan098 4 жыл бұрын
we're not suppose to do that? uh ohh
@mohammedalzamil7191
@mohammedalzamil7191 4 жыл бұрын
so where did u get in programming?
@Xaminn
@Xaminn 4 жыл бұрын
Mohammed Alzamil I have built a couple of small applications. Real estate web scraper and some audio analyzer software thing. However, it’s complete spaghetti code. Any other programmer would probably laugh lol
@mohammedalzamil7191
@mohammedalzamil7191 4 жыл бұрын
@@Xaminn lol ive been coding for about a month and built a coronavirus tracker and an ig bot that likes stuff and im currently upgrading it also built some shit witth tkinter using apis and shit
@johnvictorengland7703
@johnvictorengland7703 5 жыл бұрын
Finally somebody who explains it well, in proper English and concisely.
@DonDynAyt
@DonDynAyt 6 жыл бұрын
Hi Corey, I just wanted to tell you how much I appreciate your videos. You're doing a great job, clear and concise. Thanks!
@iamgalaxey
@iamgalaxey 6 жыл бұрын
My class doesn't explain this as well as you do i was able to easily understand this after watching this video. thank you!
@opiyosebastian50
@opiyosebastian50 5 жыл бұрын
Thank you Corey....I continue to follow and grow as a self made developer. You my best teacher!!
@danielgerman4757
@danielgerman4757 4 жыл бұрын
This type of good explaining that you do, should be taught to teachers! Thank you for all your hard work and dedication.
@soumyazyx
@soumyazyx 4 жыл бұрын
Thank you Corey for your time and effort. Keep spreading the knowledge.
@JUDOGAR
@JUDOGAR 3 жыл бұрын
Excellent! Loud and clear!!!! More than most of the paid courses...Thanks a lot Teacher Corey!
@nitkap441
@nitkap441 4 жыл бұрын
You are awesome. As I had remarked in another of your video, you are the most efficient learning resource... Each minute is worth it. In other places, I feel like a 30 minute video should ve edited to 15-18min so that I can get the real stuff... Here I get every minutes worth... The learning is very very efficient for me!
@hollyjo161821
@hollyjo161821 3 жыл бұрын
Had to donate - I've watched your Channel ALL Day. I have learned more than I deserve. Thank you!
@peschebichsu
@peschebichsu 2 жыл бұрын
Your video are many years old and still on most of the topics one of the best resscource, thanks a lot!
@VelezBiH
@VelezBiH 7 жыл бұрын
Thank you for explain the error handling in python. You are my favorite KZfaq teacher on python!
@ineedsolution
@ineedsolution 5 жыл бұрын
This the best explanation of try / except concept ever.
@mohammedalzamil7191
@mohammedalzamil7191 4 жыл бұрын
did you get better with coding it's been a year
@younghwanchae1422
@younghwanchae1422 4 жыл бұрын
The way you teach how to program is so great, not to mention the contents.
@michaelhagans965
@michaelhagans965 4 жыл бұрын
Awesome. Thanks for clearing that up for me. You can also raise your own custom exception such as: 'raise Exception('This is a custom error you can create.')
@Assanken
@Assanken 8 жыл бұрын
The most vivid and comprehensive explanations ever! Great videos.
@abdelhadialhnsh7228
@abdelhadialhnsh7228 6 жыл бұрын
I have looked around to understand this topic and finally, I found the best explanation ........good job ...please keep going and share more tutorials
@coreyms
@coreyms 6 жыл бұрын
Glad it helped make sense of the topic :)
@officesuperhero9611
@officesuperhero9611 6 жыл бұрын
Another awesome video, Corey! Amazingly clear and concise. Thank you.
@navidmohammadzadeh2141
@navidmohammadzadeh2141 5 жыл бұрын
The best tutor ever! The best in the world! Thank you so much!
@jhpk4495
@jhpk4495 6 жыл бұрын
Thank you so much thats what i need for my program! and also you helped me in mastering python! keep up the great work!.
@ManojKumar-1985
@ManojKumar-1985 5 жыл бұрын
Excellent explanation as to when to use this.Also by showing an example the concept just sits in head :-) Good job Corey
@silverflash1675
@silverflash1675 7 жыл бұрын
explained very well! thank you
@junaidjawedkhan5888
@junaidjawedkhan5888 6 жыл бұрын
This is the best explanation I've read! - Thank you!
@cibelless510
@cibelless510 4 жыл бұрын
Always a surprise video. Other guys are good too, but they are a little confuse some times. But you always very clear such as ...Begin --- middle ---End....Good for you man.
@rezamostafid8810
@rezamostafid8810 2 жыл бұрын
Corey: very clear and useful introduction of all the main features and caveats....better than the Python book I'm current using to learn python. I'm not sure if you did this intentionally but you mention some points at the beginning ( and also later on ... ) that provide the motivation for exceptions to begin with. This in turn allows much better understanding of the 'else' and 'finally' clauses as well as the 'raise' Thanks for clearing the fog in my head!
@sammavrs
@sammavrs 2 жыл бұрын
always a great feeling when my "professor" links your videos. STUDENT LOANS HERE I COME!!
@edgarlip2
@edgarlip2 4 жыл бұрын
awesome as usual !!! just wanted to add some little detail about the raise , u can do it like if(name == ''): raise Exception('name is empty , please specify a name !')
@crazyvashisth
@crazyvashisth 5 жыл бұрын
Now that's how to explain. Well done Corey😄😄😄😄🍻
@bikeshtiwari
@bikeshtiwari 5 жыл бұрын
You made me learn many concepts in python. Ur awesone teacher
@julijanaskova438
@julijanaskova438 4 жыл бұрын
Very clearly organized and explained, thanks!
@Parvej669
@Parvej669 5 жыл бұрын
Thanks for the video. I learned Exception handling from here.
@Kelvo980908
@Kelvo980908 6 жыл бұрын
Thank you! Much better than how my professor explained it.
@adamsmith5374
@adamsmith5374 7 жыл бұрын
This video helped me a great deal to wrap my head around this topic. Thank you very much!
@MrVwin
@MrVwin 7 жыл бұрын
Perfect Tutorial. Thank you Corey
@koteswararaogudla2675
@koteswararaogudla2675 6 жыл бұрын
Loved the way when you started with pass statements dude.. thank you
@A.O.U
@A.O.U 3 жыл бұрын
This is how you learn something in 10 minuteS. THANK YOU SIR , your explanation is AMAZING.
@alalhaj220
@alalhaj220 2 жыл бұрын
this is exactly what i was looking for, instead of defining all of the exceptions i wanted to print a message when an unwanted value was the input
@satyamvats5438
@satyamvats5438 3 жыл бұрын
Very Nice ! You understand us each & every deep concepts of the functions.
@genem5659
@genem5659 2 жыл бұрын
7 years later, this tutorial is still helping people! xoxo
@manjitsingh1124
@manjitsingh1124 5 жыл бұрын
Thanks for the lesson Corey !
@dp0813
@dp0813 5 жыл бұрын
word = 'currupt' try: if word != 'corrupt': raise ValueError except ValueError: print("Corrupt is spelled wrong!") >>> Corrupt is spelled wrong! :-D
@asiddiqi123
@asiddiqi123 4 жыл бұрын
LOL!
@rohanghoshdastidar1047
@rohanghoshdastidar1047 4 жыл бұрын
N I C E
@flowenglish
@flowenglish 3 жыл бұрын
hahahaha
@kenrosenberg8835
@kenrosenberg8835 4 жыл бұрын
Short and simple, great video
@joshualipovetsky2744
@joshualipovetsky2744 6 жыл бұрын
Excellent video, Corey! Thanks so much!
@oluwatobilobaadeyemi2008
@oluwatobilobaadeyemi2008 Жыл бұрын
This is a great. Simple clear concise.Thank you
@manuzsanand
@manuzsanand 5 жыл бұрын
Very well explained. Thank you.
@brolord1288
@brolord1288 Жыл бұрын
That moment when you like a video you already liked :) Great tutorial, thanks!
@szenghoe
@szenghoe 6 жыл бұрын
Thank you very much! your tutorial series is really helpful!
@marcello4258
@marcello4258 2 жыл бұрын
best tut in regards to this topic on YT this seems also to be the case for other languages not only for python
@suleymanarifcakr3609
@suleymanarifcakr3609 2 жыл бұрын
Thank you so much for sharing lots of videos! They are really so helpful!
@nirayah
@nirayah 4 жыл бұрын
Very good explanation. Thank you!
@mathieuseligmann9488
@mathieuseligmann9488 3 жыл бұрын
Thank you so much !!!! You have just helpt me a lot !!! 10 minutes and learning so much that is so great. Again thank you very much.
@akanimoakwa1892
@akanimoakwa1892 7 жыл бұрын
Thanks bro. You explained the topic so well. I am really grateful.
@akinkanju9653
@akinkanju9653 8 жыл бұрын
Corey, thanks for these useful videos. I've watched all your videos about Python. Please consider covering scraping and regular expressions. Cheers!
@coreyms
@coreyms 8 жыл бұрын
+Seun Ade Thanks for the suggestions! I'll try to put some videos together on those topics.
@urbandude823
@urbandude823 6 жыл бұрын
I've been trying to learn how to do a working try/except for like a year, and nothing made sense until now. Thank you!
@secure_the_bags620
@secure_the_bags620 4 жыл бұрын
Man thank you for making this video. I finally understand!!
@niteshtiwari1828
@niteshtiwari1828 6 жыл бұрын
Best explanation about exceptional handling
@aayushgarg12
@aayushgarg12 3 жыл бұрын
Thank you so much Corey sir. Your video helped a lot. Your video made my concepts clear about try/except.
@boombot9615
@boombot9615 3 жыл бұрын
good explanation, cleared almost all of my doubts
@soroushsoltani919
@soroushsoltani919 2 жыл бұрын
Your nice sir ! i was absent in the classroom but i had the opportunity to learn it here
@ab5848
@ab5848 3 жыл бұрын
Thanks a ton Corey🙏 I hereby pronounce you as my ultimate Guru🙏
@scarletzyy
@scarletzyy 4 жыл бұрын
Well explained. Thanks a lot, mate!
@dakota5569
@dakota5569 4 жыл бұрын
I could watch this perfectly at 1.75 for a quick recap/rundown. Take my like
@RomanReigns-ds8hs
@RomanReigns-ds8hs 3 жыл бұрын
Awesome content !! Thanks for these videos.
@SJ-vc2tz
@SJ-vc2tz 3 жыл бұрын
Very clear explanation, thank you!
@F3ND1MUS
@F3ND1MUS 4 жыл бұрын
I needed this info, THANK YOU!
@schnitzelen2
@schnitzelen2 2 жыл бұрын
Very nice explanation, greatly appreciated! 🙂
@suryapraharsha5497
@suryapraharsha5497 7 жыл бұрын
Nice and clearly explained!! thank you
@SuperMechtronics
@SuperMechtronics 3 жыл бұрын
This exception video is exceptionally excellent
@ramasubbareddy6147
@ramasubbareddy6147 6 жыл бұрын
superb explanation on exception handling in python
@ymany3277
@ymany3277 4 жыл бұрын
amazing video and very simple and clear explanation.
@papacore73
@papacore73 Ай бұрын
Clear and concise. Thanks!!!
@Sneaadler
@Sneaadler 2 жыл бұрын
I love that you, visulize this with a real error insted of faking one
@r01blue
@r01blue 3 жыл бұрын
Best ever video!!! Trank you!! Regards from Argentina.!!!!
@morteza1736
@morteza1736 8 ай бұрын
5:24 THIS IS MUCH MORE EASIER THAN READING TRACEBACK ERROR!!!!!! Thank you So much
@snssatyabhagavan
@snssatyabhagavan 4 жыл бұрын
thank you very much for this video i am struggling with it from so many days
@nikolahuang1919
@nikolahuang1919 7 жыл бұрын
too good. So clear and no strange accent.
@deveagle6193
@deveagle6193 6 жыл бұрын
LOVE your Python videos!
@gledhillholdingsptyltd2654
@gledhillholdingsptyltd2654 6 жыл бұрын
Best Python tute on the web
@danielEpifanov
@danielEpifanov 3 жыл бұрын
probably most informative video on youtube
@muralimohan7005
@muralimohan7005 Жыл бұрын
Very good explanation 👍
@alexandrucretu1016
@alexandrucretu1016 5 жыл бұрын
Your videos are very helpful, Corey! tyvm Also, just to point out that it is better to close the file (f.close()) within the finally block, because it will be executed anyway, while the else block runs only if the try clause doesn't raise an exception.
@uzomaobasi3767
@uzomaobasi3767 4 жыл бұрын
do you know why an exception is thrown when he mislabels the file name? and not the FileNotFoundError? It says ErrNo2 but shouldnt it be ErrNo1?
@akankshadubey2110
@akankshadubey2110 2 жыл бұрын
Hi Corey! very well explained. Indeed it helped. Just a request to make a video on chained exceptions.
@Ather178
@Ather178 6 жыл бұрын
Excellent explanation, thanks a lot! :)
@user-uu3us9ys4q
@user-uu3us9ys4q 3 жыл бұрын
great explanations, thanks!
@NelsonMandelanelly
@NelsonMandelanelly 8 жыл бұрын
This was helpful thanks.
@KamalNayanlotus
@KamalNayanlotus 7 жыл бұрын
very well explained ,sir !!
@alfx4356
@alfx4356 7 жыл бұрын
thanks a lot for the super clear explanation!
@gauravgupta9089
@gauravgupta9089 3 жыл бұрын
really great Content! great level of explanation. Thank you :)
@xdisasterology
@xdisasterology 6 жыл бұрын
Thanks for the clarification!
@RealToriMan
@RealToriMan 5 жыл бұрын
Best teacher ever
@DrWho2008t101
@DrWho2008t101 3 жыл бұрын
appreciate your work thanks for the video keep up the good work
@naserabuobaid9524
@naserabuobaid9524 3 жыл бұрын
Thank you, this is extremely helpful
@hassanlaghbi7047
@hassanlaghbi7047 6 жыл бұрын
Thanks! Helpful video!
@SquidScopes
@SquidScopes 3 жыл бұрын
from five years later, this is still useful.
@rycitomorell5945
@rycitomorell5945 3 жыл бұрын
You are a real life hero!
Python Tutorial: Unit Testing Your Code with the unittest Module
39:13
Corey Schafer
Рет қаралды 1,3 МЛН
Advanced Exception Handling in Python
12:06
NeuralNine
Рет қаралды 53 М.
How many pencils can hold me up?
00:40
A4
Рет қаралды 19 МЛН
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,3 МЛН
#63 Python Tutorial for Beginners | Exception Handling
15:59
Telusko
Рет қаралды 493 М.
Python's 5 Worst Features
19:44
Indently
Рет қаралды 83 М.
Automate your job with Python
6:07
John Watson Rooney
Рет қаралды 341 М.
Python Tutorial: File Objects - Reading and Writing to Files
24:33
Corey Schafer
Рет қаралды 1,7 МЛН
Python Tutorial: if __name__ == '__main__'
8:43
Corey Schafer
Рет қаралды 2 МЛН
Python exception handling ⚠️
7:39
Bro Code
Рет қаралды 53 М.