JavaScript Error handling in 9 minutes! ⚠

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

КОМЕНТАРІ • 15

  • @BroCodez
    @BroCodez  9 місяців тому +1

    // Error = An Object that is created to represent a problem that occurs
    // Occur often with user input or establishing a connection
    // try { } = Encloses code that might potentially cause an error
    // catch { } = Catch and handle any thrown Errors from try { }
    // finally { } = (optional) Always executes. Used mostly for clean up
    // ex. close files, close connections, release resources
    try{
    const dividend = Number(window.prompt("Enter a dividend: "));
    const divisor = Number(window.prompt("Enter a divisor: "));

    if(divisor == 0){
    throw new Error("You can't divide by zero!");
    }
    if(isNaN(dividend) || isNaN(divisor)){
    throw new Error("Values must be a number");
    }
    const result = dividend / divisor;
    console.log(result);
    }
    catch(error){
    console.error(error);
    }
    finally{
    console.log("This always executes");
    }
    console.log("You have reached the end!");

  • @xmorlanzz
    @xmorlanzz 8 місяців тому +11

    repetition is the mother of learning, fellow programmers!

  • @justmakeitviral4733
    @justmakeitviral4733 9 місяців тому +7

    I love these short videos....it's good for revision

  • @nut_anime
    @nut_anime 9 місяців тому +2

    the idea of the content is as impressive as ever ❤

  • @hunin27
    @hunin27 9 місяців тому +2

    i always did lots of if statements to handle errors and i thought it was the best way lol

  • @Sijo2
    @Sijo2 6 місяців тому +1

    Thank you for this tutorial video. I really helped my understanding

  • @teoanilacar
    @teoanilacar 4 місяці тому +1

    This guy is awesome!

  • @dev_ression
    @dev_ression 9 місяців тому

    nicely explained bro, thank you!

  • @s.a.r.a.01
    @s.a.r.a.01 2 години тому

    thank you for this

  • @jahazielvazquez7264
    @jahazielvazquez7264 6 місяців тому

    Clear as day! Thank you good sir

  • @subinkv6849
    @subinkv6849 6 місяців тому

    Great content..

  • @EnzoJasonCotia
    @EnzoJasonCotia 12 днів тому

    Thank you 😢

  • @dimitro.cardellini
    @dimitro.cardellini 3 місяці тому

    But why not just check if result is Infinity or NaN after we performed the division? Actually, the fact that JS doesn't fail on division by zero is an intentional feature of JS.

  • @hunin27
    @hunin27 9 місяців тому

    thanks bro

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

    🎉🎉🎉🎉🎉🎉❤