Python Tutorial: Using Try/Except Blocks for Error Handling

Поділитися
Вставка
  • Опубліковано 3 жов 2024

КОМЕНТАРІ • 485

  • @paul8683
    @paul8683 7 років тому +536

    You sir are a gift to amateur programmers.

    • @WasiMaster
      @WasiMaster 4 роки тому

      @Abishek Raju Utoobguy

    • @ciaocomestai2372
      @ciaocomestai2372 3 роки тому

      @@xfire3778 how your programming status?

    • @ciaocomestai2372
      @ciaocomestai2372 3 роки тому +1

      @@xfire3778 Wow, you learned a lot, gg

    • @REVIEWSGALATTA
      @REVIEWSGALATTA Рік тому

      Aiyoo namma mind Anga pogudhe 😂😂

    • @AGMS1234
      @AGMS1234 Рік тому

      ​@@REVIEWSGALATTAVanakkam nanbare

  • @AdamThao92
    @AdamThao92 4 роки тому +377

    Better content here than most paid-training content.

  • @waynenewark5363
    @waynenewark5363 29 днів тому +2

    I'm a retired mainframe developer just starting out using python. Thanks for this helpful video.

  • @panicbydesign7315
    @panicbydesign7315 7 років тому +122

    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.

  • @kimcato5326
    @kimcato5326 5 років тому +54

    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.

  • @johnvictorengland7703
    @johnvictorengland7703 6 років тому +5

    Finally somebody who explains it well, in proper English and concisely.

  • @twattusbobble9845
    @twattusbobble9845 Рік тому +6

    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!

  • @Xaminn
    @Xaminn 4 роки тому +408

    *Puts entire project inside a Try and Except block*

    • @narenmohan3426
      @narenmohan3426 4 роки тому +11

      LOL XD

    • @kwan098
      @kwan098 4 роки тому +12

      we're not suppose to do that? uh ohh

    • @mohammedalzamil7191
      @mohammedalzamil7191 4 роки тому +4

      so where did u get in programming?

    • @Xaminn
      @Xaminn 4 роки тому +11

      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 роки тому +8

      @@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

  • @iamgalaxey
    @iamgalaxey 6 років тому +11

    My class doesn't explain this as well as you do i was able to easily understand this after watching this video. thank you!

  • @ineedsolution
    @ineedsolution 5 років тому +18

    This the best explanation of try / except concept ever.

  • @opiyosebastian
    @opiyosebastian 5 років тому +8

    Thank you Corey....I continue to follow and grow as a self made developer. You my best teacher!!

  • @younghwanchae1422
    @younghwanchae1422 4 роки тому +1

    The way you teach how to program is so great, not to mention the contents.

  • @michaelhagans965
    @michaelhagans965 4 роки тому +1

    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.')

  • @peschebichsu
    @peschebichsu 3 роки тому

    Your video are many years old and still on most of the topics one of the best resscource, thanks a lot!

  • @soumyazyx
    @soumyazyx 4 роки тому +14

    Thank you Corey for your time and effort. Keep spreading the knowledge.

  • @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

  • @abdelhadialhnsh7228
    @abdelhadialhnsh7228 6 років тому +2

    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 :)

  • @sammavrs
    @sammavrs 2 роки тому

    always a great feeling when my "professor" links your videos. STUDENT LOANS HERE I COME!!

  • @bikeshtiwari
    @bikeshtiwari 5 років тому +2

    You made me learn many concepts in python. Ur awesone teacher

  • @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

  • @genem5659
    @genem5659 2 роки тому

    7 years later, this tutorial is still helping people! xoxo

  • @hollyjo161821
    @hollyjo161821 3 роки тому

    Had to donate - I've watched your Channel ALL Day. I have learned more than I deserve. Thank you!

  • @cibelless510
    @cibelless510 4 роки тому +1

    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.

  • @nitkap441
    @nitkap441 4 роки тому +3

    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!

  • @navidmohammadzadeh2141
    @navidmohammadzadeh2141 5 років тому +4

    The best tutor ever! The best in the world! Thank you so much!

  • @edgarlip2
    @edgarlip2 5 років тому +2

    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 !')

  • @A.O.U
    @A.O.U 3 роки тому

    This is how you learn something in 10 minuteS. THANK YOU SIR , your explanation is AMAZING.

  • @brolord1288
    @brolord1288 Рік тому

    That moment when you like a video you already liked :) Great tutorial, thanks!

  • @Parvej669
    @Parvej669 5 років тому +2

    Thanks for the video. I learned Exception handling from here.

  • @dp0813
    @dp0813 5 років тому +120

    word = 'currupt'
    try:
    if word != 'corrupt':
    raise ValueError
    except ValueError:
    print("Corrupt is spelled wrong!")
    >>> Corrupt is spelled wrong!
    :-D

  • @danielgerman4757
    @danielgerman4757 4 роки тому +3

    This type of good explaining that you do, should be taught to teachers! Thank you for all your hard work and dedication.

  • @crazyvashisth
    @crazyvashisth 5 років тому +5

    Now that's how to explain. Well done Corey😄😄😄😄🍻

  • @DonDynAyt
    @DonDynAyt 7 років тому +1

    Hi Corey, I just wanted to tell you how much I appreciate your videos. You're doing a great job, clear and concise. Thanks!

  • @soroushsoltani919
    @soroushsoltani919 2 роки тому

    Your nice sir !
    i was absent in the classroom but i had the opportunity to learn it here

  • @Sneaadler
    @Sneaadler 2 роки тому

    I love that you, visulize this with a real error insted of faking one

  • @tobyladeoghenetega4793
    @tobyladeoghenetega4793 4 дні тому +1

    Incredibly useful video
    So that was why my code kept running the except block even with the right input😅

  • @morteza1736
    @morteza1736 Рік тому

    5:24 THIS IS MUCH MORE EASIER THAN READING TRACEBACK ERROR!!!!!!
    Thank you So much

  • @junaidjawedkhan5888
    @junaidjawedkhan5888 6 років тому +3

    This is the best explanation I've read! - Thank you!

  • @nirayah
    @nirayah 4 роки тому +2

    Very good explanation. Thank you!

  • @JUDOGAR
    @JUDOGAR 3 роки тому

    Excellent! Loud and clear!!!! More than most of the paid courses...Thanks a lot Teacher Corey!

  • @VelezBiH
    @VelezBiH 7 років тому +1

    Thank you for explain the error handling in python. You are my favorite UA-cam teacher on python!

  • @austinmorara7954
    @austinmorara7954 Рік тому

    commenting seven years later😂Thank you for creating this video, Its really helped me understand Exceptions better.

  • @danielEpifanov
    @danielEpifanov 3 роки тому

    probably most informative video on youtube

  • @kenrosenberg8835
    @kenrosenberg8835 4 роки тому +1

    Short and simple, great video

  • @Kelvo980908
    @Kelvo980908 6 років тому +1

    Thank you! Much better than how my professor explained it.

  • @jhpk4495
    @jhpk4495 6 років тому +7

    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 років тому +4

    Excellent explanation as to when to use this.Also by showing an example the concept just sits in head :-) Good job Corey

  • @SuperMechtronics
    @SuperMechtronics 4 роки тому

    This exception video is exceptionally excellent

  • @silverflash1675
    @silverflash1675 7 років тому +19

    explained very well! thank you

  • @alexandrucretu1016
    @alexandrucretu1016 5 років тому +4

    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 5 років тому

      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?

  • @julijanaskova438
    @julijanaskova438 4 роки тому +1

    Very clearly organized and explained, thanks!

  • @dakota5569
    @dakota5569 4 роки тому +1

    I could watch this perfectly at 1.75 for a quick recap/rundown. Take my like

  • @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!

  • @MauriceWilliams
    @MauriceWilliams 3 роки тому

    YEEEESSSS! Soon I will have great awesome superpowers (from knowing how to code).

  • @user-pe9qg3hg3k
    @user-pe9qg3hg3k 2 роки тому +1

    I saw a video before where someone said that to use try: / except: was bad because they said if something fails it should just break, but they totally missed the point of it. Try except is super useful when paired in while loops with booleans to determine whether user input is able to be converted with no issue, for example

  • @oluwatobilobaadeyemi2008
    @oluwatobilobaadeyemi2008 2 роки тому

    This is a great. Simple clear concise.Thank you

  • @r01blue
    @r01blue 3 роки тому

    Best ever video!!! Trank you!!
    Regards from Argentina.!!!!

  • @officesuperhero9611
    @officesuperhero9611 6 років тому +1

    Another awesome video, Corey! Amazingly clear and concise. Thank you.

  • @SquidScopes
    @SquidScopes 3 роки тому

    from five years later, this is still useful.

  • @koteswararaogudla2675
    @koteswararaogudla2675 7 років тому

    Loved the way when you started with pass statements dude.. thank you

  • @SK-gn3rs
    @SK-gn3rs 3 роки тому

    I like the video even before watching...when I see it is your video....

  • @Assanken
    @Assanken 8 років тому

    The most vivid and comprehensive explanations ever! Great videos.

  • @FeedFall8
    @FeedFall8 5 років тому +4

    This video Helped ALOT! in my game development

    • @migueldomingos4570
      @migueldomingos4570 4 роки тому +1

      What are you using to make game dev in python ?

    • @tinylittleanj2
      @tinylittleanj2 4 роки тому +1

      Miguel Domingos probably pygame

    • @MohaDou
      @MohaDou 4 роки тому

      with python ? o_0

    • @FeedFall8
      @FeedFall8 4 роки тому

      Its pygame :D, btw pygames pretty good for 2D games, you just need to write efficient code to get 200+ fps on complex games

  • @mathieuseligmann9488
    @mathieuseligmann9488 4 роки тому

    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.

  • @josekodek4938
    @josekodek4938 6 років тому +5

    You have helped me really a lot in learning programming Allah Bless you Mr.Corey Schafer

  • @secure_the_bags620
    @secure_the_bags620 4 роки тому +1

    Man thank you for making this video. I finally understand!!

  • @ab5848
    @ab5848 3 роки тому

    Thanks a ton Corey🙏 I hereby pronounce you as my ultimate Guru🙏

  • @ViralKiller
    @ViralKiller 4 роки тому +47

    raise Exceptions lol, I just want to get rid of them all

    • @andrey1652
      @andrey1652 4 роки тому +5

      Lol imagine having errors pfffff

    • @aerahtv0000
      @aerahtv0000 2 роки тому

      i honestly hate try/catch and all that jazz, in c++ i could atleast choose, to use them or not, i made my own testing functions and it was better, as it was straight forward, specific to my project, doesn't clutter the code and little bit better in terms of performance.
      Now i'm learning python and looks like the only way to deal with errors in this language is this shit

  • @manjitsingh1124
    @manjitsingh1124 5 років тому +2

    Thanks for the lesson Corey !

  • @ymany3277
    @ymany3277 4 роки тому +1

    amazing video and very simple and clear explanation.

  • @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

  • @snssatyabhagavan
    @snssatyabhagavan 4 роки тому

    thank you very much for this video i am struggling with it from so many days

  • @satyamvats5438
    @satyamvats5438 3 роки тому

    Very Nice !
    You understand us each & every deep concepts of the functions.

  • @papacore73
    @papacore73 5 місяців тому

    Clear and concise. Thanks!!!

  • @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!

  • @MrVwin
    @MrVwin 7 років тому +2

    Perfect Tutorial. Thank you Corey

  • @rycitomorell5945
    @rycitomorell5945 3 роки тому

    You are a real life hero!

  • @ramasubbareddy6147
    @ramasubbareddy6147 7 років тому

    superb explanation on exception handling in python

  • @niteshtiwari1828
    @niteshtiwari1828 6 років тому +1

    Best explanation about exceptional handling

  • @adamsmith5374
    @adamsmith5374 7 років тому

    This video helped me a great deal to wrap my head around this topic. Thank you very much!

  • @akinkanju9653
    @akinkanju9653 9 років тому +2

    Corey, thanks for these useful videos. I've watched all your videos about Python. Please consider covering scraping and regular expressions. Cheers!

    • @coreyms
      @coreyms  9 років тому +10

      +Seun Ade Thanks for the suggestions! I'll try to put some videos together on those topics.

  • @RomanReigns-ds8hs
    @RomanReigns-ds8hs 4 роки тому +1

    Awesome content !! Thanks for these videos.

  • @szenghoe
    @szenghoe 6 років тому +1

    Thank you very much! your tutorial series is really helpful!

  • @alainkr
    @alainkr 4 роки тому

    Why would you unlike this video. Don't understand. Thanks Corey

  • @muralimohan7005
    @muralimohan7005 2 роки тому

    Very good explanation 👍

  • @DrWho2008t101
    @DrWho2008t101 3 роки тому

    appreciate your work thanks for the video keep up the good work

  • @paulmk2290
    @paulmk2290 3 роки тому +4

    Seriously, you should consider putting together a course on Udemy, or the like. I am here now because the instructor on the course I am currently doing assumed that I knew everything you just explained. Also, I note that you covered what you are doing properly and thoroughly. Not everybody is capable of doing that.

    • @PHXKHEEDGAMING
      @PHXKHEEDGAMING Рік тому

      😹😹😹😹😹😹😹😹😹they always assume what they are supposed to be teaching

  • @gledhillholdingsptyltd2654
    @gledhillholdingsptyltd2654 6 років тому

    Best Python tute on the web

  • @nikolahuang1919
    @nikolahuang1919 7 років тому

    too good. So clear and no strange accent.

  • @scarletzyy
    @scarletzyy 4 роки тому +1

    Well explained. Thanks a lot, mate!

  • @202ashish202
    @202ashish202 26 днів тому

    Boss...you are exception for 'all paid videos explanations' 😉

  • @akanimoakwa1892
    @akanimoakwa1892 7 років тому

    Thanks bro. You explained the topic so well. I am really grateful.

  • @SJ-vc2tz
    @SJ-vc2tz 3 роки тому

    Very clear explanation, thank you!

  • @deepakpratap3792
    @deepakpratap3792 Рік тому

    Best teacher..Thanks a ton

  • @suleymanarifcakr3609
    @suleymanarifcakr3609 2 роки тому

    Thank you so much for sharing lots of videos! They are really so helpful!

  • @akankshadubey2110
    @akankshadubey2110 2 роки тому

    Hi Corey! very well explained. Indeed it helped. Just a request to make a video on chained exceptions.

  • @sixie6e
    @sixie6e 4 роки тому

    other python videos, the person just narrates what they are doing without successfully explaining the concepts behind it. this is why you need to watch corey's videos. he doesn't make videos to show others he can code, he makes them so others can LEARN!

  • @joshualipovetsky2744
    @joshualipovetsky2744 6 років тому

    Excellent video, Corey! Thanks so much!

  • @thienviet3429
    @thienviet3429 2 роки тому

    Thanks, the new thing I know from this video is: "While you can already write two except, you are destroyed by 'except NameError and ValueError: '"