Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

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.
Previous: Fetching Data – `fetch` API & JSONNext: Working with Dates – `Date` object & Intl