Hello learners π
We have to accept one thing here Error is part of programming and fixing and learning it's to way of growing!!!!!
What is error handling in Javascript π€π οΈ ?
how it came into picture Let's understand via code π
let error = "error Handling";
console.log(error + error2);
// what it will give me, it will give me refference error and stop execution here
// It mean it will not be able to execute next line code.
console.log(
"Operation"
// Big operation not performed here ππ
);
π¦ so because of this complication error handling came into picture got it Yes
What is error handling (Exception Handling)
Error : Error it mean the program gives
Handling: Handling it mean to take care of that program
Defination:
- Javascript provide an error handling mechanism to catch run time errors using try -catch-finally block.
- Error handling handles the runtime errors in the JavaScript. try is the keyword creates the try block. Here the code that can cause exception is under the wrap under this block. The catch is the keyword creates the catch block.
// try to relate or differentiate this example with above example // which we performed ππ try{ let errors = "error Handling" console.log(errors + "" + error2); } catch(e){ console.log(e.message); console.log(e.name); console.log(e); }finally{ console.log("operation Successful"); // Yeah it workππ }
But one thing I have a doubt what is this try-catch-finally-block π€π€π€·ββοΈπ€·ββοΈ I don't understand let's understand via theoretical way see this ππ
try{
// we have to write code here in those way which will throw error
}catch(){
// As soon as the try pass error here it will catch here
}finally{
// Either try throw error or not Catch work or not it will run at any cost
}
- Error handling handles the runtime errors in the JavaScript
- try is the keyword creates the try block. Here the code that can cause exception is under the wrap under this block.
- Thecatchis the keyword that creates the catch block. Additionally, we use it to catch the exception thrown from the try block and execute the code.
- Finally, the block runs a piece of code always whether there is an exception or not.
- The throw keyword can create customized exceptions, which can be thrown based on certain conditions.
Β