Lesson 16 of 55 · javascript
Error Handling – try/catch, Custom Errors & Debugging
Duration: 9 mins
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');
Debugging tools
console.log,console.table,console.group.debugger;statement – pauses execution when DevTools are open.- Chrome DevTools → Sources → Breakpoints.