File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,13 @@ const url = "./api/people.json";
77const btn = document . querySelector ( ".btn" ) ;
88
99btn . addEventListener ( "click" , async ( ) => {
10- const response = await fetch ( url ) ;
11- const data = await response . json ( ) ;
12- displayPeople ( data ) ;
10+ try {
11+ const response = await fetch ( url ) ;
12+ const data = await response . json ( ) ;
13+ displayPeople ( data ) ;
14+ } catch ( error ) {
15+ console . log ( error ) ;
16+ }
1317} ) ;
1418
1519const displayPeople = ( people ) => {
@@ -23,3 +27,15 @@ const displayPeople = (people) => {
2327 element . innerHTML = displayData ;
2428 document . body . appendChild ( element ) ;
2529} ;
30+
31+ // console.log(random);
32+
33+ // Here "catch" will not block running the app like the above console statement does as random is not defined
34+ try {
35+ console . log ( "hello" ) ;
36+ console . log ( random ) ;
37+ } catch ( error ) {
38+ console . log ( error ) ;
39+ }
40+
41+ console . log ( "hello" ) ;
You can’t perform that action at this time.
0 commit comments