@rightcapital/exceptions
TypeScript icon, indicating that this package has built-in type declarations

1.2.20 • Public • Published

exceptions

Introduction

This library provides a set of standard Exceptions

It is inspired by the PHP's SPL exceptions

Installation

pnpm add @rightcapital/exceptions

Usage

import { RuntimeException, LogicException } from '@rightcapital/exceptions';

const logicException = new LogicException('A logic exception');

try {
  // Something
  throw new RuntimeException('Crash!', logicException);
} catch (exception) {
  if (exception instanceof RuntimeException) {
    //.... BlaBlaBla
    if (exception.isCausedBy(logicException)) {
      console.log(
        'Catch you!',
        exception.name,
        ', You are caused by',
        exception.cause.name,
      );
    }
  }
}

API Reference

Here is the API documentation for the modules included in the package.

Package Sidebar

Install

npm i @rightcapital/exceptions

Weekly Downloads

935

Version

1.2.20

License

MIT

Unpacked Size

31.3 kB

Total Files

66

Last publish

Collaborators

  • rightcapital-npm-publisher
  • hao.zheng
  • rainxright