0

Error handling in js please explain me this code

try { null.console console.log("We are inside try block"); functionHarry(); } catch(error) { console.log(error) console.log("Are you okay?"); console.log(error.name); console.log(error.message); } finally { console.log("Finally we will run this") }

4th Sep 2022, 12:24 PM
Abhishek
Abhishek - avatar
3 Answers
+ 2
If there is an error during the execution of the code in the block try, we stop the code of the try and we execute the code of the block catch. Whether there is an error or not, we finish by executing the code finally. 1/ first Line of try block make error 2/ execute catch block 3/ execute finally block If you don't use try / catch, program should crash and stop.
4th Sep 2022, 1:24 PM
Roland
Roland - avatar
0
null.console what is this
6th Sep 2022, 6:59 AM
Abhishek
Abhishek - avatar
0
Yes, null.console make an error, so code in try block stop and catch block running
6th Sep 2022, 7:28 AM
Roland
Roland - avatar