Briefle
LearnGlossaryPricing

Briefle words · Code & architecture

Custom error class

Your own named kind of error, built on the language's Error type, so code can tell different failures apart.

Say it to an AI

TypeScript getEpisode(id) service. Define custom error classes NotFoundError and ValidationError extending Error, throw them instead of strings or generic Errors, and map them to 404/400 in one httpStatus helper with instanceof checks, falling back to 500.

How an expert would brief the stronger version of “Episode lookup errors”.

See it

Try it as a puzzle →

Service function behind GET /episodes/:id in a podcast app, plus the helper that maps its errors to HTTP status codes.

Study A · the stronger one
Study B · the weaker one

Why: A declares 'class NotFoundError extends Error {}' and 'class ValidationError extends Error {}'. B throws a plain 'new Error(...)' for both.

Related words

  • Edge case
  • Guard clause
  • Swallowed exception
  • Fail fast
  • Side effect
  • Log level
  • instanceof check
  • Optional chaining

Room 4 · Errors & edge cases

Learn “Custom error class” in a five-minute lesson

Start free
AI can build almost anything. The bottleneck is saying what you want.
WordsPricingTermsPrivacyRefundsContact
© 2026 Briefle