0
0
Node.jsframework~10 mins

Handling uncaught exceptions in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to catch uncaught exceptions in Node.js.

Node.js
process.on('uncaughtException', (err) => {
  console.[1]('Caught exception:', err);
});
Drag options to blanks, or click blank then click option'
Ainfo
Berror
Cwarn
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.log instead of console.error
Misspelling 'uncaughtException'
Not passing the error parameter
2fill in blank
medium

Complete the code to exit the process after logging an uncaught exception.

Node.js
process.on('uncaughtException', (err) => {
  console.error(err);
  process.[1](1);
});
Drag options to blanks, or click blank then click option'
Aexit
Bterminate
Cend
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using process.stop or process.end which do not exist
Not exiting the process after an uncaught exception
3fill in blank
hard

Fix the error in the code to properly handle uncaught exceptions.

Node.js
process.on('uncaughtException', (error) => {
  console.error('Error:', [1]);
});
Drag options to blanks, or click blank then click option'
Aerr
Berror.message
Cerror
Dexception
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the parameter
Logging only error.message which hides stack trace
4fill in blank
hard

Fill both blanks to log the error stack and then exit the process.

Node.js
process.on('uncaughtException', (err) => {
  console.[1](err.[2]);
  process.exit(1);
});
Drag options to blanks, or click blank then click option'
Aerror
Bstack
Cmessage
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.log instead of console.error
Logging err.message instead of err.stack
5fill in blank
hard

Fill all three blanks to create a handler that logs the error, cleans up, and exits.

Node.js
process.on('uncaughtException', (err) => {
  console.[1]('Uncaught:', err.[2]);
  cleanup();
  process.[3](1);
});
Drag options to blanks, or click blank then click option'
Aerror
Bmessage
Cexit
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.error but wanting a simple log message
Logging err.stack instead of err.message here
Forgetting to exit the process