Java custom exceptions 🛑

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

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

  • @BroCodez
    @BroCodez  4 года назад +73

    // *****************************************************
    public class AgeException extends Exception{

    AgeException(String message){
    super(message);
    }
    }
    // *****************************************************
    import java.util.Scanner;
    public class Main {
    public static void main(String args[]){

    Scanner scan = new Scanner(System.in);
    System.out.print("Enter your age: ");
    int age = scan.nextInt();

    try{
    checkAge(age);
    }
    catch(Exception e)
    {
    System.out.println("A problem occured: "+e);
    }
    }

    static void checkAge(int age)throws AgeException{

    if(age

  • @MrMrdahlberg
    @MrMrdahlberg 4 года назад +76

    You're the best programming teacher on youtube! Has helped me tremendously!

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

      Isn't he really something? The introductions and conclusions really lift my mood. Even representing a dragon to defeat the YT algorithm!🤣Content is worth a million dollars! The only thing that I'm hating right now is the nostalgia the electronic music gives me at the end. My high school would play these same tracks when ending classes.😭

  • @ShinyKun
    @ShinyKun Месяц назад +3

    Sir, you are, indeed, a hero. I've just passed my programming exam with a score of 25/30.
    All of your explainations alongside my friends' taught me programming waaaaay better than the university professor and textbooks and I've aced. I'm commenting on this particoular video because it's the one I've seen the most. Absolute legend!

  • @Moritz_-fs8yp
    @Moritz_-fs8yp 3 года назад +27

    You're a legend! These 10 minutes taught me more than my professor did in 1.5 hours.

  • @joshvduh
    @joshvduh 10 месяцев назад +4

    Bro, I’m in a bootcamp right now and I swear you teach better than any teacher I’ve had. I appreciate you 🙏🏾

  • @vklmao8677
    @vklmao8677 3 года назад +14

    Udemy: We will take your money and will teach you shit
    Bro: I Am GoNnA EnD ThIS MaN'S WhOlE CaReeR

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

    Thank you, I love how you show thing without unnecessary clogging. Great video

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

    This is my best of best teachers in my programming studies

  • @Garrison86
    @Garrison86 2 года назад +5

    You rock dude! Thanks for the you are a phenomenal teacher, its all about the analogies.

  • @rebeccamonroy444
    @rebeccamonroy444 3 года назад +3

    Thank you, I understood about the custom exception, before this video, I didn't have idea how to create one. I subscribed, I'll keep watching more videos

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

    Bro, why do all this through an "exception" instead of a simple if / else statement? I am not experienced enough to have an opinion. Just trying to understand. Thank you!

    • @zero0bb
      @zero0bb 9 месяцев назад +4

      custom exceptions can also be used to show stacktrace and method calls, information like this not only improves the debugging of code it also makes it a lot cleaner and readable in comparison to bulky if else statements

    • @Reymax164
      @Reymax164 9 месяцев назад +4

      probably not needed for small programs… but in big projects it'll be better to do that.
      So knowing it is good.

    • @se7sss1
      @se7sss1 7 месяцев назад +2

      Just for clarity especially in big projects
      If you use if else for every exception you will end up having multiple conditions which will be alot confusing.
      So, instead we use try catch block so when youor someone read your code it’s alot easier to identify what the code does.

  • @thomasavery413
    @thomasavery413 2 года назад +5

    Legend!!
    thank you so much for the help!

  • @MNSRS_world
    @MNSRS_world 2 месяца назад +1

    Thank you ❤
    Very very thank you.

  • @angelcastineira2561
    @angelcastineira2561 4 года назад +9

    public class NegativeAgeException extends Exception{
    NegativeAgeException(String message){
    super(message);
    }
    }
    ///////////////////////////////////////////////////////////////////////////////////
    static void checkAge(int age)throws NegativeAgeException {
    if (age

    • @BroCodez
      @BroCodez  4 года назад +12

      I loled at "You must be born to sign up"
      xD

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

    Excellent ! Very helpful ! Thank you very much !

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

    Thanks for everything!!!! U R AMAZING!

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

    amazing explanation]

  • @RoadtoRichandRespected
    @RoadtoRichandRespected Год назад +7

    public class Main {
    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    System.out.println("Enter your height in cm: ");
    int height = scan.nextInt();

    try {
    checkHeight(height);
    }
    catch(HeightException e) {
    System.out.println("You don't reach the minimum height: " + e);
    }

    }
    static void checkHeight(int height) throws HeightException {
    if(height < 160 ) {
    throw new HeightException("You are not tall enough to go on the ride.");
    }
    else {
    System.out.println("You are tall enough to go on the ride.");
    }
    }
    }
    public class HeightException extends Exception{
    HeightException(String message){
    super(message);
    }
    }

  • @nawfalnjm5699
    @nawfalnjm5699 3 года назад +1

    your videos are very helpful

  • @SantiRayn
    @SantiRayn 26 дней назад

    thanks! your videos are good as always:)

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

    Thank you Bro Code, You're the Bro!❤❤

  • @idrisgundogdu6528
    @idrisgundogdu6528 3 года назад +1

    very useful thnaks...

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

    thanks to you i finnally understand exceptions! Thank you!

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

    nta nadi a sat

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

    Great video

  • @sergeyb6071
    @sergeyb6071 4 года назад +5

    Great tutorial! I was trying to figure out a condition which verifies if a non-numeric key was entered. I'm kinda puzzled..

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

    Thank you for your effort 😊
    Would you please make a video about do post request to a URL.

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

    Best Teacher

  • @girl6994
    @girl6994 4 года назад +6

    Sir,I am very sorry to disturb you. I wonder why in Java IO stream always use 8kb bytes to input or out put data? Why don’t we use a larger size array? If we use a larger size, don’t we just simply get read and write much faster? So why don’t we use a larger size of array? And in sql, we just need to avoid use too much times of IO, we don’t need to worry about limited 8kb, why???

    • @BroCodez
      @BroCodez  4 года назад +7

      hmmm let me do some research, that is a difficult question. I will see what I can find

    • @BroCodez
      @BroCodez  4 года назад +10

      I have not yet found the answer, but I did find some documentation that explains IO stream in depth: docs.oracle.com/javase/tutorial/essential/io/streams.html

    • @girl6994
      @girl6994 4 года назад

      Bro Code Buffered byte steams which is BufferedOutputStream and BufferedInputstream, and both of them use 8kb bytes array as buffer area which is 8192 bit.

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

    I have lab about how to make exception,
    Thank you Bro code.

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

    Nice

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

    you are great bro you so good for my feature thank you for everythings.

  • @wolanus
    @wolanus 4 года назад

    Thanks Bro. Great job. Keep on doing those vids.

  • @RahulBhatia-py1iv
    @RahulBhatia-py1iv Год назад

    You are legend 😂🎉

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

    Amazing video, helped me a lot :)

  • @shaiknafeezahmed9139
    @shaiknafeezahmed9139 3 года назад

    Thank you Bro.... This code helps me alot Bro From Bro Code Bro... ❤️👍😜

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

    Great video!!!

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

    Hey thanks a lot for the video! Quick question, on the catching side of the code, you used the "Exception e". If i put there instead of Exception e, my own exception will this be a problem in case other exceptions occur? Is it advisable to keep both the Exception e and add another catch after that for my own exception?

  • @aruldilip9430
    @aruldilip9430 3 года назад

    I can't ask for a best teacher

  • @studynotes2082
    @studynotes2082 3 года назад

    very clear~ Thanks Bro.

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

    Created something similar but made it a PokedexException that only accepts entries 1 to 1008, anything else would throw the exception.

  • @mouadessalihi9417
    @mouadessalihi9417 4 года назад

    greaaat work broooo

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

    Thank you very much

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

    Damn Bro is Amazing

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

    thanks for the vids brah

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

    thanks mate❤‍🔥

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

    nice

  • @kemann3815
    @kemann3815 3 года назад

    Lovely

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

    Thank you so much Bro!

  • @sihleeundefined1208
    @sihleeundefined1208 4 года назад +1

    Bro, what if we want to use Exceptions for a String/Strings?

  • @wolffz4304
    @wolffz4304 3 года назад

    Bro, I know it's been a long time since you uploaded this video, but i have a question about custom exceptions: is there a way to make one of those custom tooltips to surround something with a try and catch block with my custom exception faster? You know, when you type something like a dangerous method and it gives you a "quick fix" by surrounding the method call with a try and catch block by itself, is there a way to make a "custom quick fix" by myself?

  • @codex4630
    @codex4630 3 года назад

    How to handle exceptions in return type method?

  • @mumtahenahussain3849
    @mumtahenahussain3849 3 года назад

    thank you for saving me

  • @hugoresende5620
    @hugoresende5620 3 года назад +1

    static void checkXP (int x) throws XPExeption{
    switch (x){
    case 1:
    System.out.println("NIVEL 1");
    break;
    case 2:
    System.out.println("NIVEL 2");
    break;
    case 3:
    System.out.println("NIVEL 3");
    break;
    default:
    throw new XPExeption("NOT VALID");
    }
    }

  • @SoyadRahman-g3v
    @SoyadRahman-g3v 8 месяцев назад

    sir love from bangladesh but i have a question why have you used static block in this code

  • @alexshepel5599
    @alexshepel5599 4 года назад

    Nice, bro!

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

    you're the best

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

    thanks bro

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

    THANK YOU!!!!

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

    Thank you

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

    honestly idk what i am typing here ,i am just following your command sir😁...ig i can proceed to the video..yeah

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

    Nice, thanks

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

      I remember you Ivan! Hello!

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

      @@BroCodez Heya

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

    how did u extend Exception in ageException but there is no exception class???

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

      Java has an Exception class by default, like Math class.

  • @ElifArslan-l9g
    @ElifArslan-l9g 3 года назад

    thank you so much

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

    Thanks bro.

  • @youssefkhalifa04
    @youssefkhalifa04 15 дней назад

    thnks dude

  • @lamias7712
    @lamias7712 3 года назад

    Thanks

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

    thanks ,broo

  • @Arthur-g5n8q
    @Arthur-g5n8q 15 дней назад

    75 videos seen! aiming to see til 125 (bc i don't have that much interest on JavaFX)

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

    thank you

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

    ❤❤

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

    you're the bro

  • @skillR-243
    @skillR-243 3 года назад

    Adoro estos videos aunque no sé inglés xD

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

      حتى انا😂

  • @alexshepel5599
    @alexshepel5599 4 года назад

    nice, bro :^)

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

    78th. Thank you, ma Bro Sensei

  • @erek_alone3952
    @erek_alone3952 3 года назад

    i think i should see the video at first then commit

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

    Question
    Write a program to accept email address from a user and throw user defined exception if
    it does not contain @ symbol.
    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    Scanner sc =new Scanner(System.in);
    System.out.println("Enter Your Email");
    String Email =sc.nextLine();
    try{
    checkEmail(Email);
    }
    catch (Exception e){
    System.out.println("A Problem occured"+e);
    }
    }
    static void checkEmail(String Email)throws EmailException{
    if (Email = ){
    throw new EmailException("plese enter valid email:");
    }
    else{
    System.out.println("Your are Sign up ");
    }
    }
    }
    Sir What should we used in if block for verifying It Contain @symbol or not

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

    whatsup bro

  • @kirsty6108
    @kirsty6108 4 года назад

    SORRY I came from your first video I need HELP! I accidentally deleted the left hand side of the program where it says package explorer how do I get it back?!!?

    • @girl6994
      @girl6994 4 года назад

      Kirsty Holmes no way. If you use java file’s class method to delete, it will delete forever, it’s not like windows to put files in your garage bin. But if you really need to recover, I can send you a disc scanner software for you to recover. It can recover in most case, but I won’t promise you it will surely success.

    • @girl6994
      @girl6994 4 года назад

      If you use eclipse.

    • @angelcastineira2561
      @angelcastineira2561 4 года назад

      window - show view - package explorer (if you are using eclipse)

  • @amadujalloh4700
    @amadujalloh4700 4 года назад

    😎😎😎😎😎😎😎

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

    vunderbar

  • @abadiabadi3205
    @abadiabadi3205 2 дня назад

    w

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

    brooooo

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

    Ly bro 6

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

    Need rewatch

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

    algo

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

    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("Is Bro king?
    y/n");
    String answer = scanner.next();
    try {
    nonSenseFilter(answer);
    } catch(SpecificException e) {
    System.out.println(e);
    } finally {
    System.out.println("Bro is the king!");
    }
    }
    public static void nonSenseFilter(String answer) throws SpecificException {
    if (!answer.equals("y")) {
    throw new SpecificException("Stop typing gibberish!");
    } else {
    System.out.println("You goddamn right!");
    }
    }
    }

  • @archaeniac7846
    @archaeniac7846 3 года назад

    Comment

  • @ashish8-v4g
    @ashish8-v4g Месяц назад

    import java.util.Scanner;
    class AE extends Exception {
    AE(String m) {
    super(m);
    }
    }
    class Main {
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int age;
    age = s.nextInt();
    try {
    if (age < 18) {
    throw new AE("You are not 18");
    } else {
    System.out.println("You are 18+");
    }
    } catch (AE e) {
    System.out.println("An error occurred: " + e.getMessage());
    }
    }
    }

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

    mlmlm

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

    comment

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

    Yo just wanna say that GOD loved the world so much he sent his only begotten
    son Jesus to die a brutal death for us so that we can have eternal life
    and we can all accept this amazing gift this by simply believing in him (Jesus) asking for the forgiveness of your sins
    and forming a relationship with heavenly father. ..>>>>....

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Год назад

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

    Thank you

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks

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

    Thank you

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

    Thanks

  • @mohammedzaidkhan5687
    @mohammedzaidkhan5687 11 дней назад

    Thanks