FlashKeepers

JavaScript · JavaScript

JavaScript Error Handling and Debugging

Try catch blocks, custom error types, and common debugging techniques in JavaScript, each explained with a short example.

29 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone
What is the syntax for a try-catch block?
try { code that might fail } catch (error) { handle error }
What happens if an error is thrown inside try without a catch?
The script stops, the error propagates up, and execution halts unless caught higher up
Name three properties available on an Error object
message, name, stack
What error does accessing an undefined variable throw?
ReferenceError
What error does calling a non-function throw?
TypeError
What error is thrown for invalid JSON syntax?
SyntaxError
What is the purpose of the finally block?
Code that runs after try or catch, regardless of whether an error occurred
How do you manually throw an error?
Use the throw keyword: throw new Error('message') or throw someValue
How do you create a custom error type?
Extend the Error class: class MyError extends Error { constructor(message) { super(message) } }
What does the stack property of an Error contain?
A string showing the call stack at the point the error was thrown, useful for debugging
What is console.log primarily used for?
Printing general information to the console for debugging
What is the difference between console.error and console.warn?
console.error is for errors (red), console.warn is for warnings (yellow or orange)
What does the debugger statement do?
Pauses code execution at that line when developer tools are open, allowing step-through inspection
How do you catch errors from a Promise?
Use .catch() method: promise.catch(error => { handle error })
How do you use try-catch with async/await?
try { const result = await someAsyncFunction() } catch (error) { handle error }

14 more cards in the app