#63 Python Tutorial for Beginners | Exception Handling

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

КОМЕНТАРІ • 420

  • @akashsahni9407
    @akashsahni9407 6 років тому +188

    Mr Perfect = Navin Reddy Sir

    • @Busy_mind24
      @Busy_mind24 2 роки тому +1

      Python=Navin reddy sir💕

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

    "The general doctor" 👍
    Nicely put. My compliments!

  • @ShoaibKhan0701
    @ShoaibKhan0701 4 роки тому +69

    Itna to college wale bhi nahi karate jitna navin ji samjha dete h ❣️❣️❣️

  • @sam.mankar
    @sam.mankar 4 роки тому +102

    Telusko = 1
    Navin_Reddy_Sir = 100
    try:
    print("Telusko + Navin_Reddy_Sir")
    except:
    print("you don't have any errors, Sir.")
    finally:
    print("you are still the best")

  • @aryanfalke5751
    @aryanfalke5751 4 роки тому +65

    I literally learned the entire python language through your videos. Tysm for great videos and simplified explanation

  • @srikanth-ry8lp
    @srikanth-ry8lp 4 роки тому +31

    mamulu racha kadu, I was almost ready to pay for python classes and i found this channel. THE BEST channel to learn coding.

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

    Sir your teaching style is innovative and the tidbits that you say in-between is what makes you a great teacher.
    I've been taught by many teachers and I can say the level at which teach, for which other teachers get paid a lot, but you deliver all this for free is commendable.
    Thank you very much Sir for rejuvenating my passion for Python.

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

    i was struglling with this topic from long time. u made it just like clear water. thank u

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

    This is how you teach. keep it basic/simple. Thanks, great job.

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

    Amazing Teaching skill. God bless you sir.

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

    Thanks a lot Sir!

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

    thank you for this lesson, well digested

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

    Excellent explanation. You are an extraordinary teacher🙏

  • @jfaguile
    @jfaguile 8 місяців тому

    Pretty clear explanation; thanks for sharing your knowledge.

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

    what is the need of finally: if we can just print('resource closed") outside will that make sense?

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

      I thought the same but it does look tidier to the eye... as a logical block of code before embarking on some other idea... kind of like paragraphs in writing prose...

    • @aryanfalke5751
      @aryanfalke5751 4 роки тому +10

      If you do not have the finally clause and you get an error the file won't close. Finally ensures that regardless of the errors taking place in the program , it would perform the task mentioned.

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

      @@aryanfalke5751 i think that u had failed to understand the question correctly. he is asking that what is the need of finally, if we just simply put the 'resource closed' statement outside all the blocks of try and except.

    • @raodyc
      @raodyc 4 роки тому +8

      Let just say in your except block you mentioned only 1 type of error ( Value error) and when you run the code you divided any number with 0
      In that case the "resource close" statement not going to run
      Finally: ensure that every last block of code execute even if there are multiple errors

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

      *See if you write 'resource closed' outside then it will get printed only when there is not an error because the execution stops when there is an error previously*

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

    Hey Telusko, got an incorrect output please check it:
    It is not asking for input in following case:
    a=5
    b=0
    try:
    print("Resource opened")
    print(a/b)
    k=int(input("Enter a number :"))
    print(K)
    except ZeroDivisionError as e:
    print("Hey, error and cause of error is :",e)
    except ValueError as e:
    print("Hey, Invalid Input :",e)

    except Exception as e:
    print("Hey Something went wrong :",e)

    finally:
    print("resource closed")
    output:
    Resource opened
    Hey, error and cause of error is : division by zero
    resource closed
    Question is here why it is not asking me to enter a number K ?

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

    Simplification in learning program called Telusko 💥

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

    fantastic explanation.

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 2 роки тому

    Thanks a lot for such a great explantion!

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

    a=5
    b=2
    try:
    print("resource open")
    print(a/b)
    k=int(input("enter a number"))
    print(k)
    except ZeroDivisionError as e:
    print("Hey, you cannot divide a number by zero",e)
    except ValueError as e:
    print("Invalid input", e)
    except Exception as e:
    print('something went wrong...',e)
    finally:
    print('resource closed')

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

    Wow. A big thumbs up for this video. Made my day.
    Thank you.

  • @сойка-и8й
    @сойка-и8й 6 років тому +9

    Sir...thank you for your python beginners tutorials...sir are you going to upload videos on python frameworks and advanced libraries... Like sckit learn numpy opencv etc..? please let me know sir...

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

    Best python teaching.. Love the way of teaching...🖤🖤

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

    great sir got 100% there...thnks

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

    best and short explanation!!

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

    sir you are superb

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

    marvelous bro keep it up👍

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

    explanation is exceptional/awesome but only complain is about the cuts in the video which strains eyes...please try to minimize the cuts. everything else is phenomenal.

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

    Amazing work there, will you be making tutorials of creating GUI in python?

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

    Can we execute 2 except blocks ?

  • @AshrafulHussainKhan
    @AshrafulHussainKhan 3 роки тому +6

    It was always confusing for me about the error handling. You made it crystal clear today. I like your simplicity in teaching complex concepts.

  • @vojtechbrecka201
    @vojtechbrecka201 3 роки тому +6

    So I am slowly approaching the end of your Python course, Sir, and I have to thank you. I have started just a few weeks ago as a total beginner, and because of you, I can now write a simple applications, and (and that's most important) I can think as a programmer which made learning other languages a lot easier for me. Thank you, Sir Navin Reddy

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

    Good tut

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

    Great explanation.
    Also I like all your catch phrases. Eg, "Hold on" and "For those with Java, C++ background will be familiar with this" and "You might be wondering" and "What would happen if" and "Oh thats weird, what if i do this.."

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

    What if you want to continue prompting the user until they enter valid input? I can't get the loop right, it will except the error once if they enter a character instead of an integer, then it will prompt the user for valid input but if they enter a character again it won't handle the exception again and stops my execution.

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

    Hi Navin,
    As you mentioned, if we want some piece of code irrespective of whether an exception was caught or not, then, we use finally block.
    So, wanted to ask, what if we don't use finally block and instead write that piece of code post our except block. Then too, our piece of code will execute whether or not an exception was caught or not.
    Will there be a difference? if yes, what's the benefit of using finally block instead of writing that code after except block?
    Example with finally block:
    a = 5
    b = 0
    try:
    print("DB connection started")
    print(a/b)
    except Exception as e:
    print("Exception caught !!", e)
    finally:
    print("DB connection closed")

    The same example without finally block:
    a = 5
    b = 2
    try:
    print("DB connection started")
    print(a/b)
    except Exception as e:
    print("Exception caught !!", e)
    print("DB connection closed")

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

      Since you have given the Exception keyword, it will handle all the exceptions. Try this:
      a = 5
      b = 0
      try:
      print("DB connection started")
      print(a/b)
      except ValueError as e:
      print("Exception caught !!", e)
      print("DB connection closed")
      In the above case the print("DB connection closed") statement would never run. but now try this and the print("DB connection closed") always runs even if any error occurs.
      a = 5
      b = 0
      try:
      print("DB connection started")
      print(a/b)
      except ValueError as e:
      print("Exception caught !!", e)
      finally:
      print("DB connection closed")
      Hopefully it made sense now

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

      @@vjnimbalkar thanks Vijay. It helped.

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

    Thank you very much for this tutorial! It was that part of coding what I have never understood exactly, until I've seen your video!

  • @fatihdilmac
    @fatihdilmac 5 років тому

    He is genius thank you so much

  • @yadatis5905
    @yadatis5905 5 років тому

    Thank you so much sir 😊. It's very helpful for me

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

    Sir, I got one doubt. If we want two exceptions at a time how can we do it?

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

    Nice videos Navin sir
    These are very helpful to me. Thank you a lot for your hard work.

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

    You're a great instructor, thanks for sharing these concepts in a way that beginners can actually understand :)

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

    i wish i had a teacher like u in my school!!!!!!!!!!!!

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

    Will this work instead of finally??
    Try:
    print("resource open")
    print(a/b)
    except Exception as e:
    print("Hey, you cannot divide by 0", e)
    print("resource closed")

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

    Sir you are great with thier easy explanation.i learn most of the thing in python for your channel .it is very good and easy to understand.
    Thank you sir...

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

    When you were talking about different doctors in examples, I yelled, ''DENTIST DOCTOR!".
    xD

  • @navinn.luthrianavinn.luthr9532
    @navinn.luthrianavinn.luthr9532 3 роки тому +2

    Hello Sir your way of teaching and the presentation is amazing 👍👍

  • @sujalsubramani1543
    @sujalsubramani1543 2 роки тому +1

    u made easier sir better than my teachers or frnds thanks a lot

  • @shubhamgohel007
    @shubhamgohel007 2 роки тому +5

    Navin sir :- God of Programming for me.....Helped me get through interview and many concept 😘

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

    what would be the use of finally if anything under will be executed anyway?

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

    *Best video in this topic*
    Thank You Sir

  • @NoName-py4dj
    @NoName-py4dj 5 років тому +1

    a question arises how ur process finished with exit code 1 instead of 0...at the bottom of the code or page

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

    I have started loving python because of your teaching sir hats off to you🙏🙏🙏🙏🙏

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

    A good class that can easily confuse if one is not careful.....otherwise you are Mr Good in this field, as a starter, I feel challenged to when I will be there. Again thanks to my classmates because the comments we write here are also resourceful by far when I read, understand and
    run them, I get informed of extra things. Big up guys.

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

    I think finally is a useless function, instead of finally without indentation if we put print then also at any cost it will print so what is the use of finally.

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

      No that's not the case. Suppose you have else and finally clauses. Now suppose something wrong (error) happens in Else which generates an exception, the program will terminate. But if we have finally block, interpreter will first execute finally block and then will generate the exception. Its not possible without finally block.
      Secondly, in user defined function, finally can have a different behavior.
      Watch my video discussing this in detail.

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

    do freeze the background animation, video file size will be less than half

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

    print ("Beauty Right!")

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

    Awesome

  • @karthick9408
    @karthick9408 3 роки тому +6

    A good teacher doesn't need a whole day for any good concept simply this much time is enough
    Thank you sir 👍

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

    thank you so much, i was able to figure out my hw because of this video

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

    navin sir thopu velithe appu...........

  •  4 роки тому

    easy... this have in js.

  • @t11oaa8
    @t11oaa8 3 роки тому +2

    Can I like this a million times? Thank you Telusko!

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

    Great teaching style sir all doubts are clear👌👌👍👍👍👍🎂

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

    Can 2 except run at a same time ?

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

    Am I the only one that actually opens the fridge and leaves it open 😂 just looking at the food lol. You’re the best bro you explain so well I love your videos

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

    Any1 on last minute preparation

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

    Thanks and appreciate you Sir for ur effort. I have the same question which Abhi asked. Will you upload videos on NumPy, pandas and other libraries. How much python knowledge we should require to get started with a job in python? Do we require knowledge of all libraries and framework like Django, pylons? To start a job in python what we skillset do we actually require in python. Please guide SIR..Thanks a lot

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

    Can we use try multiple times

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

    Nice explanation sir.... Thank u so much🤗

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

    What if have an error in division as well as in the taking input from the user will it show both the error at the same time
    Plz Reply.

    • @lokuambati2800
      @lokuambati2800 5 років тому

      Ys is also got the same doubt but when I gave b=0 i didn't get "number given in input as output" I got zerodivison error only ...

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

    U should go the doctor skin, your head skin is green. Try to fix that man! Make a double render...

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

    Thank you so much man! You just saved my weekend!

  • @1Tbiribiri
    @1Tbiribiri 3 роки тому

    Learned something you ask?...dude literally taught me what I couldn't understand in 3 lectures in my class..
    Also finally doesn't give a fuc-

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

    The introduction of finally was just like a climax in movie 😁

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

    The best video for Exception handling in UA-cam. Nailed it sir.

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

    Navin Sir I am just a 15-year-old kid interested in programming. In school, we are taught JAVA language. I know the basics but still, you teach so well that in my 10th grade currently sitting at home during the lockdown I stay awake until 11:00 pm after completing the studies just because u teach with so many interesting real-life examples. So just love the way u teach. I have watched 63 videos in 8 days. I am really enjoying. Thank u!!!!!!!!

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

      @Aanshumaan Shrijai VII C Roll No. 37 Thats Good!! I was told one thing you know by one of my connections on LinkedIn just to motivate you here is the thing:
      Udit Rathod
      You should explore never stop exploring ... just keep in mind you have to be Dora the explorer because that's what I do.
      That's the man UDIT RATHOD who told me pretty inspiring things!! If possible connect with me on LinkedIn we can discuss a lot of things!! You can also get ideas from me we can exchange challenges lot more.

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

      @Aanshumaan Shrijai VII C Roll No. 37 Then how can we be in contact?

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

    Sir there is one more method: with statement

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

    Interesting that k is accepted even though it appears to be an undefined variable
    Modified your code to accept inputs a and b:
    a = 0
    b = 0
    try:
    print("Resource open: ")
    a = int(input("Enter a numerator: "))
    b = int(input("Enter a denominator: "))
    print(a/b)
    # k = int(input("Enter a number: "))
    #print (k)
    except ZeroDivisionError as e:
    print("You cannot divide by zero", e)
    except ValueError as e:
    print("Invalid input")
    except Exception as e:
    print("Something went wrong")
    finally:
    print("Resource closed")

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

    తెలుగు :-థన్యవాదములు

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

    I understand this topic only by ur video, thanks a lot

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

    (Siddesh): Use of "finally" is not clear..... Even without using "finally" if we just printed "resource closed" post "exception" block if will still work,,,, What's the significance of using the feature "finally"...Doesn't make sense to me yet Navin.. Can you please help clarify,...
    Note: I could see similar questions posted but didnt have a clear explaination yet

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

    I wish I could give some more likes to sir's lectures

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

    Sir 🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻The way you are teaching 👌🏼👌🏼👌🏼👌🏼NAA buthoo na bavishyath🤝🤝🤝🤝✊✊

  • @ashvinsawarkar1399
    @ashvinsawarkar1399 11 місяців тому

    00:08 Types of Errors in Python
    02:07 Runtime errors occur during execution and can be caused by user input, missing files, or network issues.
    04:01 Even if you get an exception or error, the execution should not stop.
    05:52 To solve the problems of user comprehension and execution stopping, use a try-except block in Python.
    07:52 Exception handling allows us to handle errors and execute alternate code when an error occurs
    09:41 Always ensure to close a resource that you open in a try block.
    11:35 Exception handling in Python allows execution of code, whether an exception occurs or not.
    13:39 Exception Handling in Python
    15:35 Exception Handling in Python with try, except, and finally blocks
    Crafted by Merlin AI.

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

    Sir i have a doubt:
    a = 3
    b = 0
    If b != 0:
    print(a / b)
    else:
    print("can't enter zero in b)
    Sir, if this problem solved by if else, then i should we use Try-expcept. Please help i want to understand exception handling

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

    Very clear explanation Sir...Thanks a Lotttttttttttttttttttt Sir

  • @bubblebath2892
    @bubblebath2892 5 місяців тому +1

    You really have a knack for teaching ...brilliant

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

    how to handle mutiple exception like if we have divide by zero error and also Value error at same time..this code is just jumping out of try block for the first exception and not detecting second one...tried with break/break_continue..but not getting expected output

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

    Sir inside try if we have 2 statements with 2 errors, when we execute them just after the first error it is getting out to that exception handling and printing that but it is leaving the 2nd error inside the try. So if we want it too to be handle should I write it in another try statement or any other method available ? [ try:
    print(5/0)
    print(int('p')) consider indentations]

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

    what if two errors are to be executed at once, for say in the above example if we use b=0 and give "p" as input. Only one error is executed(it jumps out ). How to make all execution at once. Please answer my question

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

    Navin your videos are amazing.
    Navin, please specify else block as well. i.e, try block for checking any error, except block will handle the error, else block will execute if there is no error, and finally block will excecute regardless the result of try and except block.

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

    Can we use if else statement instead of using except statement again and again . I think it will work for perfectly

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

    will only one except block run if we got an error? Consider if we have a general exception(Exception as e) and a specified exception(say., ValueError)......

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

    Tqq so much sir. You nailed it.i didn't understood this concept java but you made it clear in Python

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

    what is the difference between raise and return exception? If there are multiple exceptions we don't know, can all be handled in the same except Exception as e? How to handle errors from multiple processes in multiprocessing in Python?

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

    Rule # X of Programming: Never assume the user will not do something stupid. If you have goofed around in video games you know why.

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

    Hi. I've been trying to insert an input statement but everytime i try to put a character, the code is just running. As if i havent put a character. No error, no nothing. Just the statement in quotes
    Help anyone?

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

    accept vs except: syntax error

  • @RaushanKumar-to7rw
    @RaushanKumar-to7rw 8 місяців тому

    love the way you teach. Ah just had a little request may be you should have used "You may loose crores of rupees" instead of using "You may loose billions of dollars".