Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extended-exceptions

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extended-exceptions

Easy custom js exceptions for node & browser

  • 0.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

extended-exceptions.js

Introduction

Allow easy declaration of custom exceptions.

Also defines common exceptions for Javascript that are missing in the standard : RuntimeError, NotImplementedError, InvalidArgument, OutOfRange, etc.

Works in node.js + browser, AMD.

Full testsuite. No dependencies.

Usage

Throwing an exception :

define(
[
	'extended-exceptions'
],
function(EE) {
	"use strict";

	throw new EE.RuntimeError("Oups !");

Defining our own exceptions inheriting from an existing one :

define(
[
	'extended-exceptions'
],
function(EE) {
	"use strict";

	// inheriting from RuntimeError
	var CustomError = EE.create_custom_error("CustomError", EE.RuntimeError);
	
	throw new CustomError("Oups !");
	
	...
	
	console.log( caught_error.name );
	console.log( caught_error.message );
	console.log( caught_error.stack );

Catching and testing exceptions :

Predefined exceptions

Note : we keep the "error" naming scheme of standard javascript.

  • Error (standard)
  • ExtendedError
  • LogicError
  • InvalidArgument
  • LengthError
  • OutOfRange
  • RuntimeError
  • NotImplementedError
  • UnknownEnumValueError
  • IllegalStateError
  • InvariantNotMetError

Unit tests

in the 'spec' folder. See also readme.txt in the 'test_runner' folder.

Keywords

FAQs

Package last updated on 25 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc