Python tricks: All there is to know about Exceptions

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024

ความคิดเห็น • 44

  • @alphainfinitum3445
    @alphainfinitum3445 2 ปีที่แล้ว

    This is the one video you want to watch. This topic is particularly very confusing on Cisco Networking Academy. Watching this before heading over there is definitely a good idea. You can tell that this guy is a formidable teacher because he is able to cover all the essentials that you need to start writing and reading code in one short video. Thank you very much mate.

  • @yoninonasade
    @yoninonasade 4 ปีที่แล้ว +3

    one of the most useful videos i have ever seen in TH-cam.
    your are my friend a dame good teacher.

  • @fabulousfabio8228
    @fabulousfabio8228 2 ปีที่แล้ว

    I really love the rigorous way in which you explain things. Thanks

  • @sujataroberts3025
    @sujataroberts3025 6 ปีที่แล้ว +3

    I tried to learn this from a few sources before I finally understood from watching this. Thank you!

  • @juliannash890
    @juliannash890 6 ปีที่แล้ว +12

    As someone learning Python, your videos are fantastic :) Keep them coming!

    •  6 ปีที่แล้ว +1

      +Julian Nash thank you!

  • @talmadhoun
    @talmadhoun 6 ปีที่แล้ว +5

    You know your stuff and you explain it very well. You're a great teacher. Thank you!

  • @lexinexiai
    @lexinexiai 3 ปีที่แล้ว +1

    Great content, rare content

  • @AlexanderLebedev_sortafreel
    @AlexanderLebedev_sortafreel 7 ปีที่แล้ว +6

    Amazingly useful video!

  • @fuanka1724
    @fuanka1724 6 ปีที่แล้ว +5

    Thanks for making these awesome videos, you are a great teacher! :)

    •  6 ปีที่แล้ว +1

      Glad you like them!

  • @adeyeyeayomide4442
    @adeyeyeayomide4442 5 ปีที่แล้ว +2

    waooh! This is concise, succinct and informative

  • @Phantastischphil
    @Phantastischphil 4 ปีที่แล้ว +2

    Thank you. I was searching for the code behind exceptions while using SOLO LEARN. Thank you for explaining that they are objects and how to construct and tailor specific instances!

  • @springinfialta106
    @springinfialta106 7 ปีที่แล้ว +3

    It would be helpful to have a talk describing multiple exceptions within a block. Some programmers would say that each block should just do one very specific thing and would only require one try...except. However, sometimes you are doing a few very related things such as working with files and each of those steps might throw an exception. You don't necessarily want to chop up that piece of code into a bunch of separate functions.
    Even in your Factorial example. You could have multiple checks:
    1) Is the type correct?
    2) Is the passed in number an integer?
    3) Is the passed in number >= 0
    How are those tests integrated together? I've seen things like this which seem over the top:
    try
    code
    except
    exception
    else:
    try
    code
    except
    exception
    else:
    try
    etc
    Is there a better way?

    •  7 ปีที่แล้ว +1

      The details of course depend on the situation and the programmer's sense of aesthetics. But as a general thought: If you have multiple checks, you can generally do them sequentially, one after another; so a deeply nested structure (which is awful) like your example is seldom necessary. And when it comes to input validation, type hints might also come in handy (th-cam.com/video/rytP_vIjzeE/w-d-xo.html). But at the end of the day: If you need to check a lot of things, you'll inevitably end up with a lot of boilerplate code!

    • @Usammityduzntafraidofanythin
      @Usammityduzntafraidofanythin 5 ปีที่แล้ว

      There's also if else, which gives another layer. Taken from channel SentDex

    • @jyvben1520
      @jyvben1520 ปีที่แล้ว

      have functions that each test 1 condition, with specific try/except + raise the_error("message")
      and the main code has a generic try/except Exception as e, with the many functions in the try block.
      try:
      test_is_num(a_value)
      test_is_int(a_value)
      test_is_pos(a_value)
      # here we can do the work or in the else block
      except Exception as e:
      print("Error: bad input", a_value)
      print(e) # optional
      else:
      print("good input, we can work with this")
      finally:
      pass

  • @m.preacher2829
    @m.preacher2829 4 ปีที่แล้ว +1

    very clear explanation,thanks

  • @cmdlp4178
    @cmdlp4178 7 ปีที่แล้ว +1

    You can catch SyntaxErrors when importing or running code with eval/exec.

    •  7 ปีที่แล้ว

      +cmdLP that's a good point, yes.

  • @pizzaboiiiiiiiiiiiiiiiiiii1882
    @pizzaboiiiiiiiiiiiiiiiiiii1882 3 ปีที่แล้ว

    keep going dude, way to hawaii

  • @denispmaciel
    @denispmaciel 6 ปีที่แล้ว +1

    Thank you!

  • @gabrielkomanderzapata3189
    @gabrielkomanderzapata3189 5 ปีที่แล้ว

    Nice video many thanks

  • @FitLife6767
    @FitLife6767 6 ปีที่แล้ว +1

    Yeah this one was very useful... It seems it was made specifically to address my issue...Thank you very much!

  • @Dopeboyz789
    @Dopeboyz789 5 ปีที่แล้ว

    How do you use this method in a df

  • @ELHAUKEZ
    @ELHAUKEZ 5 ปีที่แล้ว

    def riddle():
    try:
    return 1
    finally:
    return 2

  • @antongeorgiev1704
    @antongeorgiev1704 5 ปีที่แล้ว

    Very nice series, thank you!
    fyi, saying there is no logic behind 0! = 1, just def, hurts my mathematician's hearth ;(

  • @schogaia
    @schogaia 4 ปีที่แล้ว

    What is the benefit of using try: else:?
    I just put everything in the try block.
    I would appreciate if someone could explain this to me.
    Thank you

    •  4 ปีที่แล้ว +2

      If you include too much code in the try block, it becomes difficult to know where Exceptions come from. So it's good practice to include as little code as possible in the try block.

    • @schogaia
      @schogaia 4 ปีที่แล้ว

      @ thank you for the answer and thank you for great videos

  • @davidreynolds9649
    @davidreynolds9649 7 ปีที่แล้ว +1

    What is the document/environment you are using to display this?

    •  7 ปีที่แล้ว +3

      It's a Jupyter Notebook, which is basically an IPython terminal in a webbrowser. Very useful!

    • @davidreynolds9649
      @davidreynolds9649 7 ปีที่แล้ว +1

      thnx .... looks very cool :)

  • @maxvinella941
    @maxvinella941 6 ปีที่แล้ว

    very interesting! thanks

  • @vaibhavashrivastava9310
    @vaibhavashrivastava9310 5 ปีที่แล้ว

    "i have a data frame with columns ID and date, If date is invalid how my python program can tell me which ID indexed with invalid date"

    •  5 ปีที่แล้ว

      You can use the `isnull()` method. So say that your DataFrame is called `df` and your column is called `date`, then you can get the (indexes of) invalid dates with `df.date.isnull()`.

  • @bondbreaker3096
    @bondbreaker3096 6 ปีที่แล้ว

    more video please

  • @amateruss
    @amateruss 6 ปีที่แล้ว

    WTF I thought your cam was a random picture of a dude on a beach having a vacation until I pressed the play button.

  • @radonspace2098
    @radonspace2098 3 ปีที่แล้ว

    I owe you a coffee.

  • @dhananjaykansal8097
    @dhananjaykansal8097 5 ปีที่แล้ว

    AWESOMEEEEE

  • @OrgBrent
    @OrgBrent 3 ปีที่แล้ว

    Are you Dutch?

    •  3 ปีที่แล้ว +1

      Ja dat klopt!

  • @boobubuo
    @boobubuo 6 ปีที่แล้ว

    esle ???? why ??? try esle before except block (inside "try except")... lol