Exception Handling in Java Tutorial

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

Комментарии • 279

  • @TheSisovic
    @TheSisovic 2 года назад +491

    Just to say, i'm an IT student and whenever i see something new about Java in my college i go here to yt and look up on your account since i found out that you're much eaiser to understand than my professors, asistants and mentors are. THANK YOU FOR MAKING ME PASS MY EXAMS!!! xD

    • @jbrfr94
      @jbrfr94 Год назад +12

      Ditto, he explains everything so clearly, it's insane how much more i can understand from here than from any of my classes lol

    • @bubble0
      @bubble0 Год назад +3

      Same, but for me i think its the excellent live coding that makes it so easy to understand :D

  • @jaredcampbell1975
    @jaredcampbell1975 2 года назад +38

    Thank you for imparting your knowledge to all of us on RUclips! I pay attention to the Java lectures at my University, but you have a way of explaining it better than my professors.

  • @christopherboisvert6902
    @christopherboisvert6902 2 года назад +1

    I am student in computer science in my last year and you thought me some stuff I didn't know. Good Stuff!

  • @zeppelinmexicano
    @zeppelinmexicano 9 месяцев назад +1

    Good advice to use Finally{} to close connections, etc. Then no matter what might explode in the try { } it won't abandon the connections or leave files open.

  • @micleh
    @micleh 2 года назад +103

    3:57 - It's exceptional how you tackle the topics of your videos so comprehensively in such a limited timeframe. I wondered why a colleague of mine could not explain to his students the hierarchy of exceptions, while you cover it in the basics of your tutorial here.
    Your videos are so good that I'm constantly thinking of designing a worksheet where one of your videos is the topic and my students have to prepare the topic of the lessons with the help of both - a flipped classroom principle.
    And before I had actually finished your video, I was thinking about whether you would cover the execution of code after an exception is thrown, and voilà, you also covered that at 9:44.
    Please continue making videos about Java related stuff.

    • @Kfimenenpah
      @Kfimenenpah 2 года назад +3

      In my experience people who don't have a complete understanding themselves have problems explaining it it others :D

    • @azuboof
      @azuboof Год назад

      @@Kfimenenpah as Einstein said

    • @sauvikgoel591
      @sauvikgoel591 9 дней назад

      If you happen to create that worksheet, pls do share it with us also!! Please 🙏

  • @computer.tutorials
    @computer.tutorials 8 месяцев назад +1

    Legendary explanation! Thank you so much, John😄

  • @SaviorOfZeDamned
    @SaviorOfZeDamned Год назад

    Subscribing because I’m in class for Java now and your videos have literally explained the content 100x better than the block of instruction. Thank you for being so clear!

  • @Eljamo_0
    @Eljamo_0 Год назад

    Thank you so much for your videos I am studying a java module and I just wish they explained stuff as simply and nicely as you do!

  • @robertoenriquechavezrodrig731
    @robertoenriquechavezrodrig731 Год назад

    Bro, thank you so much! Your videos are amazing, as a java developer myself, I learn so much from your videos! Even with one year of experience already. God bless you bro and regards from Russia!

  • @protector4286
    @protector4286 Год назад

    bro my uni uploads shitty presentations and if youve missed something tough shit. thank god for your channel.

  • @AdrianTregoning
    @AdrianTregoning 11 месяцев назад

    When I get stuck I usually come to Coding with John, and then 100% of the time I get unstuck. Thank you.

  • @ikramuddinofficial
    @ikramuddinofficial Год назад

    this is first time when i saw your video. I hope now i can learn whole java coding here

  • @davidkopec9442
    @davidkopec9442 7 месяцев назад

    You are an awesome teacher and code writer. Thank you.

  • @AdityaRaj-xo3hn
    @AdityaRaj-xo3hn 3 года назад +9

    Very helpful video!! You explained all things very clearly
    By the way, what is use of 'throws' keyword &
    Does it make a difference when used with unchecked exceptions?

  • @codingcoder602
    @codingcoder602 Год назад

    Man I would have had to read a 100 Pages or more to get less than what I got from your 10 Minute Videos. Thank you very Much!!!

  • @waleedffx
    @waleedffx 2 года назад

    Your video is very informative, thank you for taking the time to help all who need java help

  • @jacobr9741
    @jacobr9741 2 года назад +18

    Thanks for helping us all through Dev School John, you're very articulate and entertaining to boot! I'm sure i speak for us all when i say "We appreciate you".

  • @laharibasu9731
    @laharibasu9731 Год назад +18

    The best Java instructor out there. Your videos are a binge watch thing. Thanks for making them simple and interesting. ❤️

  • @Coccoutube
    @Coccoutube Год назад

    You're a great teacher John; thanks for sharing you're knowledge with us :)

  • @pavankumarn2775
    @pavankumarn2775 2 года назад

    hello john, i learnt java by watching your tutorial videos you makes me easy to understand and i'm very thankful to you....
    will u do videos about user-defined exception....thank you

  • @maxpoweroverdrive
    @maxpoweroverdrive Год назад +2

    So, is he the Johny Sins of Computer Science?

  • @mahhingaminggate5028
    @mahhingaminggate5028 Год назад

    Bruh you are a life saver .

  • @Tuxon24rus
    @Tuxon24rus 2 года назад +13

    Hello, John!
    First of all thank you for your videos, they help us a lot!
    I was wondering why line 17 at 11:00 wasn't executed. I thought 'return' in try block is related to this block and it should've forced to exit this 'try'. Or 'try' isn't considered as a method (if not, does it also apply for 'try with resources'?), thus 'return' is making to exit the 'main' method?

    • @CodingWithJohn
      @CodingWithJohn  2 года назад +15

      Good question! A return statement will return out of the method completely, not just outside of the try block. So in this case that return exits the main method, ending the program.
      You'll almost never use a return statement in the main method, and just let it complete the main method as usual. This was just to illustrate that the finally block still gets executed, even though it returns out of the method without executing the print at line 17.

    • @Tuxon24rus
      @Tuxon24rus 2 года назад +2

      @@CodingWithJohn Thank you so much!

    • @zepptonian
      @zepptonian 2 года назад +1

      Tuxon24rus, you may be thinking of the *break* statement, which will exit a block.

  • @mahbod95
    @mahbod95 6 месяцев назад

    soo clean, clear and concise. Thank you.

  • @derechte6086
    @derechte6086 8 месяцев назад

    Thank u my prof doesnt care but I do and u helped me a lot

  • @tanmaykolase2098
    @tanmaykolase2098 5 месяцев назад

    You are simply genius!🙌🏻

  • @themattster1989
    @themattster1989 2 года назад

    Subbed and liked, this guy is great at explaining, Thanks John.

  • @binary-star1of20
    @binary-star1of20 2 года назад +12

    Thank you John. You always make it easy to understand. You've really helped me, you have no idea.

  • @manavneekhra5276
    @manavneekhra5276 2 года назад

    To the point videos. Keep making good content John.

  • @hameheroj4030
    @hameheroj4030 11 месяцев назад +1

    Guys, you can forget all these videos out there and just watch this one. Everything is fine explained here!

  • @Dzikrullah_999
    @Dzikrullah_999 Год назад

    Thanks John. Super clear!

  • @DhruvinMistry69
    @DhruvinMistry69 3 месяца назад

    Great explanation , wish i knew your yt channel earlier

  • @christopherfrog2371
    @christopherfrog2371 2 года назад +2

    I was curious and checked if code from finally block runs even when an Error is thrown in try block - yes, the code was executed :)
    However I only simulated OutOfMemoryError by manually throwing it from method - I'm wondering what will happen when the error is thrown when there actually is no more memory available, will the code from finally statement be executed?
    Have a great day everyone!

  • @imdonkeykonga
    @imdonkeykonga 2 года назад

    thank you! that was extremelly interesting!

  • @jeremiahberndt7809
    @jeremiahberndt7809 Год назад

    Love your videos, maybe this is wrong or pedantic but wouldn't it be more accurate to say the exception goes "down" the call stack instead of "up"?

  • @6821965
    @6821965 2 года назад +2

    Also you can use try with resources block, to close all connections, without needing to use finally block.

  • @vidyasindhudubey5807
    @vidyasindhudubey5807 2 года назад

    Remember statements inside the finally block execute no matter what!!

  •  2 года назад +1

    if you put a return on the try, finnaly will still run?

  • @user-pr9pq8en2d
    @user-pr9pq8en2d 2 года назад

    You are amazing man....

  • @kerwinso
    @kerwinso 2 года назад +4

    Great vid as always John. Can you please also explain the "throw" and "throws" keywords? I've seen "throws" in a method signature, but wasn't sure exactly what that did.

    • @CodingWithJohn
      @CodingWithJohn  2 года назад +7

      Thanks! Well I don't have a video on "throw" specifically, but you basically just use it when you want to explicitly throw an exception in a certain situation.
      if (someParameter == null) {
      throw new IllegalArgumentException("Hey someParameter can't be null!");
      }
      Then whatever code is calling this code has to handle that exception however they see fit.
      "Throws" is used in the method signature when the method could throw a certain kind of exception, and it's not being caught anywhere within that method. It mostly has to do with "checked" exceptions. There's a good explanation on how it's used in my most recent video here:
      ruclips.net/video/bCPClyGsVhc/видео.html

  • @rayverN17yo
    @rayverN17yo 2 года назад +2

    Cant believe this dude doesn't have million of subs. Many time I just watch those videos recreationally haha

  • @alexarditti9416
    @alexarditti9416 3 года назад +5

    John I just want to say thank you. Your videos and explanations are so helpful.

  • @mayankgupta2543
    @mayankgupta2543 2 года назад

    My friend told me sins has a utube channel, did not know he also teaches coding

  • @wayneinteressierts9973
    @wayneinteressierts9973 Год назад

    Great as always. Thank you sir! :)

  • @vikasgowdaja6881
    @vikasgowdaja6881 2 года назад +1

    Love❤ From India U r Simply Amazing😊 it feels like whatever the Concept be it becomes easy when u explain it

  • @yassermouhajir8462
    @yassermouhajir8462 2 года назад +4

    Thank you very much for taking the time to explain this subject in such a magnificent
    way.

  • @shanisb95
    @shanisb95 Год назад +2

    How does it become so SIMPLE when it is YOU who explain it 😃 Another great video, thanks !

  • @Stl71
    @Stl71 2 года назад +2

    I would also like to add, that if you want to do something in java with exceptions and you don't know all the exceptions included, a good ide as Eclipse does this for you.

    • @aidancurtis6581
      @aidancurtis6581 2 года назад

      You can also throw a generic Exception that will catch all, it's quite common to see specific exceptions followed by a generic catch all exception block. IMO

  • @manar2404
    @manar2404 2 года назад +1

    you explained it better than two-hour class, can you explain GUI components

  • @jagi7976
    @jagi7976 2 года назад +1

    Throw and catch… bruh 🤯

  • @jyli8487
    @jyli8487 2 года назад

    Thank you

  • @MHF-go9sd
    @MHF-go9sd 2 года назад

    thank you, sir

  • @velavanfilmsyoutubechannel
    @velavanfilmsyoutubechannel 2 года назад

    thank you john sir

  • @DhruvPatravali
    @DhruvPatravali Год назад

    saving my life fr

  • @EnriqueMoranG
    @EnriqueMoranG 7 месяцев назад

    You're the man!

  • @D3Jia
    @D3Jia 2 года назад

    HAHA pokemon exception handling got me XD

  • @ericbarlow6772
    @ericbarlow6772 2 года назад

    Why did you not use the throw statement to throw the exception back to the system? I learned about 20 years ago to throw exceptions back to the system or it could cause problems for more complex programs.

  • @DiaborMagics
    @DiaborMagics 21 день назад

    How about you tell it to exit the program when an exception happens, which you wouldnt normally do because thats why you have exception catching in place... but, will finally still run before exiting???
    Anyway, either I missed it or you didn't touch on it, but why would you not do "pokemon catching"? Programmers and especially new one, cant possibly know every type of exception that exists and can be thrown. So why not just always use the standard Exception? Easier on memory or something?

  • @chilipismysignature5031
    @chilipismysignature5031 Год назад +2

    My dude, I absolutely love your videos. I'm currently 2 years into my BA in CompSci and whenever I don't fully understand something I watch your videos and It makes it a lot more clearer. I usually watch slowly, coding along with the video and adding notes as I go. The way you explain things is just leveled up way beyond any of the university CompSci teachers I've encountered. Also you seem like a cool dude lol. Was wondering if you were ever planning to add to your Java course? Most of the topics within, I'm pretty comfortable with. Just curious if you were ever thinking of going further ahead into more like intermediate (idk?) level concepts, maybe like DataStructures/Algorithms etc.

  • @InvinciRD
    @InvinciRD 10 месяцев назад +1

    i WANT TO KNOW FROM WHICH COLLEGE DID YOU COMPLETE YOUR GRADUATION FROM

  • @gulnarahuseynova1718
    @gulnarahuseynova1718 2 года назад

    Thank you)

  • @karasutsuki1733
    @karasutsuki1733 Год назад

    If I can just catch all exceptions using the Exception e, why would I specify which ones I want to catch, just for the custom message fitting? Or is it an efficiency thing

  • @Lexyvil
    @Lexyvil 2 года назад

    I'm just confused about the "throws" keyword now. Would appreciate an explanation on it~

  • @gettingup100
    @gettingup100 2 года назад +2

    Hi. John! Enjoying every single one of your videos. I just wish you were around when I was back in college. You would have saved me a ton of time spent reading all kinds of manuals. Keep up the great work!

  • @vivekneupane8807
    @vivekneupane8807 Год назад +1

    Great man, soo simple and so much in so little time. Perfectly synced video!!

  • @Meppoy
    @Meppoy Год назад

    Thanks for the vid! It was illuminating, though kinda hard to follow. The jumps between different versions of the code forced me to stop it and duplicate the lines in order to try them by myself. Can't say if it's a problem, really, but that's my genuine feedback, so take it or leave it). Once again - big thanks for the explanations.

  • @secretsorcerer
    @secretsorcerer 2 года назад +1

    Thank you very much Sir
    You're a great teacher
    Thanks for the last example
    Cleared all my doubts

  • @davidkpadehyea269
    @davidkpadehyea269 Месяц назад

    I have a question guys! why wouldn't you just always use the 'Pokémon' catch exception every time if it catches everything why bother using so many of the hierarchy?

  • @ruchikapanigrahi4704
    @ruchikapanigrahi4704 Месяц назад

    What is gonna happen if we catch a different type of exception but not the ones that actually happened? Like in this case, what if we catch ArrayIndexOutOfBoundException?

  • @johncusack4730
    @johncusack4730 8 дней назад

    Will the finally block be executed if, for instance, we have System.exit(0); in the try part?

  • @dvbroyo7127
    @dvbroyo7127 4 месяца назад

    Thanks for the video. Im knew to programming and the only thing im kinda missing are some practical use cases for those try and catch.
    For example why dont we put before Interger.parseint an if statement which makes sure its of type int? Where is the different to try-catch? which are pros cons? are there other methods to avoid or handle exceptoins?

  • @expertgamers9713
    @expertgamers9713 2 года назад

    hello you teach it very well thanks, can I know what IDE for java you are using, thanks

    • @CodingWithJohn
      @CodingWithJohn  2 года назад

      Thanks! I'm using Eclipse in this video, but IntelliJ in the more recent videos.

  • @Bogo0112
    @Bogo0112 Год назад +1

    If there is an error in the catch block, will finally still run?

    • @CodingWithJohn
      @CodingWithJohn  Год назад

      Unless you explicitly exit the program or a meteor hits your computer before it gets to the finally block or something, it will ALWAYS execute the finally block.

  • @CyberWookie505
    @CyberWookie505 9 месяцев назад

    Would it be possible for you to move your IDE's console output to the bottom of the screen? The video of you talking is covering it up. /// Your videos are so helpful. Thank you so much for what you do.

  • @bubochkana
    @bubochkana 7 месяцев назад

    Can someone please explain me, why the @Override annotation is not used for the child classes for the eat() method?

  • @ache4342
    @ache4342 8 месяцев назад

    Amazing video. Thank you so much. But that finally block seems completly avoidable. Closing a Connection can also be done in the try and all the catches or if youre not leaving that code segment just after the try catch

  • @tissemyren
    @tissemyren Год назад

    2 things: How do i find what exception a specific line/code gives? And what is the difference between the finally block and just writing the "End here" line without the finally

  • @anyname8803
    @anyname8803 Год назад

    a little addition : the code inside "Finally" will execute except if there is SYSTEM.EXIT() in the "try catch"

  • @chisomemmanuel6160
    @chisomemmanuel6160 Год назад

    Best Tutor ever ❤... Much love from here bro... Who else noticed from the video at length 11:02 that the last line of code didn't execute to print out "End here" or is it because of the return keyword?

  • @sagarraut4794
    @sagarraut4794 Год назад

    @coding with John...so understandable videos, please make one video on java wrapper classes and wrapped keywords

  • @Molotom
    @Molotom 2 года назад +1

    Thanks for the video! It's fun to learn about fringe cases like the return statement in finally :)

  • @alexdickey9542
    @alexdickey9542 Год назад

    Good topic! Would you have any videos on Maven setup with Java and Eclipse or JDeveloper IDEs?

  • @Matias-eh2pn
    @Matias-eh2pn 4 месяца назад

    What if we WANT the program to fail when an exception occurs? is it good practice to just use if else statements?

  • @kunalkheeva
    @kunalkheeva 2 года назад

    Great as always! But 11:51 why didn’t it print 3 from the try block?

  • @muhammadatif717
    @muhammadatif717 2 года назад +1

    Please stop showing your head in thumbnails

    • @CodingWithJohn
      @CodingWithJohn  2 года назад +1

      For some reason this is one of my favorite comments ever

  • @skfotografie
    @skfotografie 2 месяца назад

    This video was really helpful to get into the exception topic. Thanks!

  • @IvanPopov
    @IvanPopov Месяц назад

    Nice. I only wish the "try-catch-with-resources" was also in the video.

  • @SchnurriTV
    @SchnurriTV 2 года назад

    Ty mate. I was searching for why the finally block even exists for a long time. But now that i know it too runs even after a return is called, it pretty much clear

  • @IlyesMaya
    @IlyesMaya 10 месяцев назад

    why every java programmer is bald ?
    NO OFFENSE BTW

  • @GratefulCoder
    @GratefulCoder 9 месяцев назад +1

    You are nothing less than blessing to us Java programmers, Thank You John.

  • @dandendrasingh7326
    @dandendrasingh7326 2 года назад

    Nice video thanks

  • @chuckbaranoski6184
    @chuckbaranoski6184 2 года назад

    Good video!

  • @zeeg1529
    @zeeg1529 6 месяцев назад

    Thanks for the very good explanation, great job! a couple things I would add to the video:
    Autoclosable and try with resources (you did talk about DB connections/Files you wanna close in finally block, would be great to mention Autoclosable there too).
    But I see that you have a separate video on checked vs unchecked, which I was about to suggest putting here as well, perhaps there's another one on try with resources too.
    All in all, thanks again and keep up the good work!

  • @ikramuddinofficial
    @ikramuddinofficial Год назад

    John sir,your way of explaining is really nice. please guide how i become a good coder like you

  • @CHIRONJEETB7
    @CHIRONJEETB7 2 года назад +1

    Thank you John for all the videos, exceptional explanations.

  • @Lexyvil
    @Lexyvil 2 года назад +1

    This was the best video I could find for a refresher on how to handle exceptions. Very well done!

  • @donvxnks
    @donvxnks 5 дней назад

    I needed this, I'm 20 and I know that I need advice from the right people

  • @iGleeson
    @iGleeson Год назад

    Handle this exception! This was an EXCEPTIONally useful video tutorial!

  • @リンゴ酢-b8g
    @リンゴ酢-b8g 2 года назад

    All objects within the Java exception class hierarchy extend from the Throwable superclass. Only instances of Throwable (or an inherited subclass) are indirectly thrown by the Java Virtual Machine (JVM), or can be directly thrown via a throw statement.

  • @ercancaglayan4594
    @ercancaglayan4594 2 года назад

    asking to much money for course. in udemy 12.999 similar course.