Exception/Error Handling/Holding/Catching - with in the program Syntax errors: raises due violation of language rules while typing the code. -correct/modify the code the according to the language rule. -how to identify? - compiler/interpreter Runtime error: raises while executing the program. when a runtime a error occurs at one line of the program program terminates immediately with out executing the rest of the lines. this is called productivity loss. -due to non availability of resources either fully or partially. resources are files, memory, hardware devices, other softwares, other services etc. -due to wrong or invalid input of the data -invalid - size, type, format - violation of client business rules Logical errors: mismatch between the expected output and actual output. - verify the steps taken to solve the problem, and correct them. Controllable errors: no impact on the program , able to avoid the abnormal termination of the program. Uncontrollable errors: -hardware/harddisk crash -power Pre-Defined errors : according to language. User-Defined errors : according to client. x console.log('x : ' + x); ReferenceError: x is not defined ---------------------------------- var d = Array(-9); console.log('size of d : ' + d.length); RangeError: Invalid array length ---------------------------------- var CustomerName = 'John Miller"; console.log(CustomerName); SyntaxError: Invalid or unexpected token ---------------------------------------- var x = 10; var y = 2; var z = 0; console.log("x : " + x + " y : " + y + " z : " + z); z = x/y; console.log("x : " + x + " y : " + y + " z : " + z); ------------------------- observe the output: var x = 10; var y = 0; var z = 0; console.log("x : " + x + " y : " + y + " z : " + z); z = x/y; console.log("x : " + x + " y : " + y + " z : " + z); x : 10 y : 0 z : 0 x : 10 y : 0 z : Infinity --------------------------- console.log('start of the program : '); for(i=1;i<=5;i++) { console.log('i ' + i); } for(j=9001;j<=9005;j++) { console.log('j ' + j); } console.log('end of the program'); --------------------------------- console.log('start of the program : '); for(i=1;i<=5;i++) { console.log('i ' + i); } var m = Array(-9); // termination due to error - without executing the code after the array line console.log('code after the array statement : '); for(j=9001;j<=9005;j++) { console.log('j ' + j); } console.log('end of the program'); output: ------ i 1 i 2 i 3 i 4 i 5 C:\Users\malli\OneDrive\Desktop\JSApp\index.js:6 var m = Array(-9); ^ ^ RangeError: Invalid array length ----------------------------------- Note: as there is no any mechanism/code to catch the runtime error inside the program , program terminates abnormally without executing the rest of the code after the error occurred line. try catch throw finally Error ------------------------------------------- console.log('start of the program : '); for(i=1;i<=5;i++) { console.log('i ' + i); } try { var m = Array(-9); // termination due to error - without executing the code after the array line } catch { } console.log('code after the array statement : '); for(j=9001;j<=9005;j++) { console.log('j ' + j); } console.log('end of the program'); ---------------------------------------- case2: ------ console.log('start of the program : '); for(i=1;i<=5;i++) { console.log('i ' + i); } try { var m = Array(-9); // here an error object is created with error information // that created object is throwned from here implicitly } catch(e) { console.log(e.message); } console.log('code after the array statement : '); for(j=9001;j<=9005;j++) { console.log('j ' + j); } console.log('end of the program'); --------------------------------- start of the program : i 1 i 2 i 3 i 4 i 5 Invalid array length code after the array statement : j 9001 j 9002 j 9003 j 9004 j 9005 end of the program -----------------------------------