InvalidValue

Thrown to indicate that a variable has unexpected value.

Source:
InvalidValue.js, line 24
Examples
var value = 1;
var checked = InvalidValue.check(value, 0);       // Throws an exception
var checked = InvalidValue.check(value, 1);       // OK
var checked = InvalidValue.check(value, 0, 1, 2); // OK (multiple expectations)
Value Checking
var value = 3;
try {
  InvalidValue.check(value, 0, 1, 2); // Throws
} catch (e) {
  console.debug( e.info.checked  ); // 3
  console.debug( e.info.expected ); // [0, 1, 2]
}
Using .info for debug inside 'catch' block

Extends

Exception

Members

readonlyinfo any

Additional informations for debug.

Inherited From:
Exception#info
Source:
Exception.js, line 23

Methods

staticcheck(value, …expected)any

Checks if value matches with the expected values.
If it does, returns value untouched. Otherwise, triggers an exception.

The triggered exception holds value and expected as .info.checked and .info.expected.

Parameters:
Name Type Attributes Description
value any

A value to check

expected any <repeatable>

Expected value(s)

Source:
InvalidValue.js, line 62
Returns:

the value argument untouched if it has no problem

Type:
any

expects(value)boolean

Returns true if value equals to or is included in info.expected. Otherwise false.
Recommended for using alongside of InvalidValue.check method.

Parameters:
Name Type Description
value any

An expectation

Overrides:
Exception#expects
Source:
InvalidValue.js, line 42
Returns:
Type:
boolean
Example
value = 2;
try {
  InvalidValue.check(value, 0, 1); // Throws
} catch (e) {
  if (e.expects(0)) { ... } // true
  if (e.expects(1)) { ... } // true
  if (e.expects(2)) { ... } // false
}

trigger()any

Throws this exception if handler option is not set.
If handler option is set, calls it and returns the result.

Inherited From:
Exception#trigger
Source:
Exception.js, line 41
See:
Exception.option
Throws:

This exception

Returns:

The result of option.handler function

Type:
any

Documentation generated by JSDoc 3.6.6
on
using docolatte theme