Lesson 16 of 55
javascriptError Handling – try/catch, Custom Errors & Debugging
9 mins
Course progress29%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 16 of 55
javascript9 mins
Keep these ideas in mind as you work through the lesson.
Synchronous errors are caught with try…catch.
try { JSON.parse(badJSON); }
catch(e){ console.error('Invalid JSON', e); }
Asynchronous errors (Promises) use .catch() or try…catch inside async/await.
Custom Error classes:
class ValidationError extends Error {
constructor(message){ super(message); this.name='ValidationError'; }
}
throw new ValidationError('Invalid input');
console.log, console.table, console.group.debugger; statement – pauses execution when DevTools are open.