Try / Catch & Exceptions | Java | Tutorial 25

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

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

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

    Great job on explaining this. I am in my second semester of my software development program and I was working all day on my assignment in for my Java class. I am 35 and going back to school with no programming experience at all. Thanks to your video I got a way better understanding of this and it helped finish my assignment. I needed a few if statements but I got it covered! Thanks dude!

  • @xxaviersanchezz-personal
    @xxaviersanchezz-personal 6 ปีที่แล้ว +29

    Dude, I honestly love all your tutorials! I was looking for some tutorials online and I was like boring... boring... boring... BINGO! I love this channel.

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

      boring boring maybe no boring possible BINGO bro your clown

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

      @@gunnarkennedy3292 hes bare funny what do u mean??

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

      I agree, I love this channel.

    • @yankswap
      @yankswap หลายเดือนก่อน

      5 years ago… how’s your coding journey going since then?

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

    Thanks Mike, this really helped me out despite programming for almost 5 years!

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

    who the hell could dislike such an exceptional tut video? probably a competitor lol

  • @EuroUser1
    @EuroUser1 5 ปีที่แล้ว +52

    My constructive criticism:
    Catching exceptions for the sake of catching them is not a good idea. You should classify exceptions in two groups: expected exceptions (one can expect that some users will provide a wrong input) and unexpected (you can't expect that an array will go out of boundaries, deep inside your code).
    If the exception is expected, you should provide a path for the program to recover and keep working. Like asking the user for new input.
    If the exception is unexpected, you should log it, probably let your program crash, and fix your code later. So that the exception is properly handled or no longer possible, after the fix.
    For instance, if a bank transaction throws an unexpected exception, it's better to abort the transaction altogether, rather than giving away your money without sufficient guarantees. In fact, the exception may be due to a hacker who is tampering with your interface in order exploit bugs.
    In general, the checked/unchecked labelling that Java provides for exceptions is a good start for your expected/unexpected classification. However, a wrong-input exception that may be expected (when the input is provided by a human) can come out of the blue when that same input is provided by a database (which is not supposed to make that kind of mistake).

    • @yankswap
      @yankswap หลายเดือนก่อน

      In your example of telling the user it was the wrong input and asking for a valid input, what if they then entered the wrong input again? Should you catch and throw another Exception? How far down the rabbit hole does it go? Or is there a better way where you can prompt the user to keep entering inputs until a valid one is entered?

    • @EuroUser1
      @EuroUser1 หลายเดือนก่อน

      @@yankswap There is a way to keep the user inside a loop, until a valid input is entered. But I can't remember the syntax details.
      I wrote the original comment more than five years ago, and I stopped programming shortly after. I found a different job that suited my needs better. So I have forgotten much of my Java, now.

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

    You deserve more money then my programming teacher.

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

    Hi Mike, this is just mind blowing delivery!!!

  • @shahrzadmaftoun5831
    @shahrzadmaftoun5831 3 ปีที่แล้ว +2

    Thanks Mike! Could you please explain the difference between throw and throws and when we use them in a video?

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

    lmao. "You put in the wrong stuff. How dare you??" always great to learn AND laugh.Thanks :)

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

    Thanks, I've been struggling to understand the concept of the try and catch exception.

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

    This is a great supplement to the material that I am learning now. Thanks for making this video!

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

    resume:
    1) catching exceptions
    2) can catch some speficic type of exceptions ( catch ( typeofexc e) ...)
    3) errors are different from exceptions: are more bad than exceptions.
    4) do not catch errors, not reccomended.

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

    very good lecture

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

    Golas~monitor errors ~no eexecution and handle them

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

    it's very nice example (try/catch )-kindly give some more example .and thank you again boss

  • @RealNaps
    @RealNaps 5 ปีที่แล้ว +3

    Mastering java

  • @Abby-fh7hv
    @Abby-fh7hv 3 ปีที่แล้ว

    You are the best, thank you so much for these videos.

  • @shantanu925
    @shantanu925 4 ปีที่แล้ว +1

    I just can't thank you enough!

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

    S:get a number from user
    E:whats went wrong /class in java /data type ~store

  • @إسماعيل-ط6خ3ض
    @إسماعيل-ط6خ3ض 3 ปีที่แล้ว

    Thanks Mike.

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

    thank you kind sir

  • @ahmaddawood9691
    @ahmaddawood9691 5 ปีที่แล้ว +1

    EXCELLENT

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

    Thanks Mike!

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

    How can I input this Try/Catch in your last video named Building a Multiple Choive Quiz. I think it would fit perfectly there

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

    I feel that this topic could get "real complex, real fast." Is it possible for us to add additional functionality after the "catch" criteria is met? I am sure there is an easy way to reset to the System.out.println("enter a number: "); part of the code after the try/catch has prevented the code from failing, I just wonder what that way is.

    • @gunnarkennedy3292
      @gunnarkennedy3292 5 ปีที่แล้ว +1

      cough cough while loop! for loop maybe if your good :)

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

    Great video, t!hank you

  • @fzdz4069
    @fzdz4069 4 ปีที่แล้ว +1

    How to use TRY/CATCH inside a nested FOR loop so it wouldn't stop the program or print out nonsense?

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

      I think that it will stop the program and get out of the loop to throw the exception

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

    I love you.

  • @Nbak-cw7jx
    @Nbak-cw7jx 3 ปีที่แล้ว

    How about an exception if you input number instead of a letter? is there any?

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

    Can someone provide in the reply section some further and/or more advance knowledge about using try and catch? Maybe counteractions for most usually encountered problems with exceptions and errors? It would be a great help!

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

    Int [ ] numbs={1,2,3};
    System.out.println (nums[5]);
    System.out.print ("enter a number");
    Hasilya Exception in thread "main" java.lang.ArrayIndexOutOfBondExeption

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

    hear after @3:55

  • @nikolasioakimidis3003
    @nikolasioakimidis3003 4 ปีที่แล้ว +1

    The only thing I dont understand is what e is on "exception e"

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

      I think it's just a letter assigned as a variable.... like int i.

  • @shamikchakraborty3341
    @shamikchakraborty3341 4 ปีที่แล้ว +1

    i came here to learn why "throws" is used.

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

    Catch(arrayindexoutofboundsexception e | input ismatchexception) e)

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

    }catch (Throwable e){
    }catch (Error e){

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

    2:15 huhhuu
    lol.....

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

    Show your picture on thumbnail, this way people who like your vids will find them faster.

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

    Scanner keyboardInput=New Scanner (system.in);
    System.out.println ("enter a number");
    Scanner keyboardInput=New Scanner (system.in);
    System.out.println ("enter a number");
    double num =keyboard input.nextDouble( );
    }catch (Exeption e) {
    System.out.println("invalid
    Input");
    Hasilnya
    Enter a number :a
    Invalid input
    System.out.println (e);
    Hasilnya
    Enter a number :a Java.util.InputMissmatch exception

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

    try {
    System.out.println(numbs[5]);
    double num=keyboarInput.nextDouble( );
    System.out.println(num);
    }catch (ArrayIndexOutOfBondExeption e);
    System.out.println ( e);
    }catch(InputMismatchExeption e); {
    System.out.println("Invalid input");
    }catch(Exeption e)
    Hasilnya enter a number:
    =a
    Invalid input