1.0.0 • Published 11 years ago
xcore-exceptions v1.0.0
Exception.io: JavaScript
A collection of custom exception classes written in JavaScript.
Inheritance Hierarchy
Error
└── Exception
    ├── ArgumentException
    ├── InvalidInputException
    ├── NotImplementedException
    ├── NotSupportedException
    ├── NotFoundException
    ├── UnauthenticatedException
    └── UnauthorizedExceptionClasses
Usage
Initiate any one of the exception classes.
if (item == null) {
    throw new NotFoundException("Item not found.");
}Check the type of exception we are dealing with:
var err = new Exception();
err instanceof Exception               // → true
err instanceof Error                   // → true
Exception.prototype.isPrototypeOf(err) // → true
Error.prototype.isPrototypeOf(err)     // → true
err.constructor.name                   // → "Exception"
err.name                               // → "Exception"
err.message                            // → "No description"
err.toString()                         // → "[Exception] No description"
err.stack                              // → prints the stack traceHandle specific exception types using exception's constructor property:
try {
  foo("valA", "valB");
}
catch (e) {
  if (e instanceof ArgumentException) {
    console.error(e.toString());
  }
  else if (e instanceof InvalidInputException) {
    console.error(e.toString());
  }
  else {
    console.error(e.toString());
  }
}Supported Platforms
Creator
License
Exception.io is released under the MIT license. See LICENSE for details.
1.0.0
11 years ago