Skip to content

onury/custom-error-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Errors in JavaScript

Custom errors are useful when you want to track code with context-specific information. There are several ways to define a custom error in JavaScript. But since inheritance is not a first-citizen feature in JS (until ES2015); there's also so much discussion on how to define a proper custom error.

This module tests various implementations for custom errors, widely used by developers; such as methods making use of Error.call(), Object.create(), new Error(), Object.setPrototypeOf(), extends (ES2015) and util.inherits (Node). See /errors directory for included implementations.

What we expect from a custom error implementation is:

  • e.constructor.name MUST get our custom error name.
  • E.prototype MUST inherit from Error.prototype.
  • e.message MUST be set.
  • e MUST be an instance of Error.
  • e MUST be an instance of CustomError.
  • e.stack MUST be set and should have line-tracable info.
  • e.tostring() MUST return error name and/or message.
  • ({}).toString.call(e) SHOULD output "error".
  • and some more...

npm i custom-error-test to install.

Test

Run npm start which will output test results to console for the current Node.js environment. And will also generate an HTML file, which will display results for the used browser.

Better, you can directly view this page for testing your current browser.

Screenshot

License

MIT.

About

Compare and test various custom error implementations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy