File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
part1 (Basics)/built-in-objects Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -13,3 +13,62 @@ let error = new Error("Something failed");
1313console . log ( error . name ) ; // "Error"
1414console . log ( error . message ) ; // "Something failed"
1515console . log ( error . stack ) ; // Stack trace info
16+
17+ // Common Error Types in JavaScript
18+ /*
19+ INFO: 1. Error
20+ The base error object. You'll usually use this when no specific error type fits.
21+ */
22+ throw new Error ( "Generic error" ) ;
23+
24+ /*
25+ INFO: 2. ReferenceError
26+ Accessing a variable that doesn't exist.
27+ */
28+ console . log ( abc ) ;
29+
30+ /*
31+ INFO: 3. SyntaxError
32+ Code is written incorrectly and can't be parsed.
33+ */
34+ eval ( "if true { console.log('Oops') }" ) ;
35+
36+ /*
37+ INFO: 4. TypeError
38+ Using a value in an invlaid way (e.g., calling something that's not a function)
39+ */
40+ const x = 42 ;
41+ x ( ) ;
42+
43+ /*
44+ INFO: 5. Range Error
45+ A number is outside an allowable range.
46+ */
47+ let arr = new Array ( - 1 ) ; // Invalid array length
48+
49+ /*
50+ INFO: 6. EvalError
51+ An error related to the eval() function.
52+ Modern JS rarely throws EvalError anymore.
53+ */
54+
55+ /*
56+ INFO: 7. InternalError (Non-standard / browser-specific)
57+ */
58+ function recurse ( ) {
59+ recurse ( ) ;
60+ }
61+ recurse ( ) ;
62+
63+ /*
64+ INFO: 8. AggregateError
65+ Represents multiple errors at once - usually from Promise.any() or similar async code.
66+ */
67+
68+ const error1 = new AggregateError (
69+ [ new Error ( "Error 1" ) , new Error ( "Error 2" ) ] ,
70+ "Multiple failures" ,
71+ ) ;
72+
73+ console . log ( error1 . name ) ; // AggregateError
74+ console . log ( error1 . errors ) ; // Array of errors
You can’t perform that action at this time.
0 commit comments